Cviko v R - linearne modely
Created: 2012-04-23 - 12:19
x = c(1,1.5,2,2,2.5); y = c(3,5,6,6,5);
x,y;
x;y;
cor(x,y);
plot(y ~ x);
abline(lm(y~x),col='red');
cor.test(x,y);
vys = lm(y~x);
summary(vys);
x = c(1,1.5,2,2,2.5); y = c(3,5,6,6,7);
cor(x,y);
cor.test(x,y);
vys = lm(y~x);
summary(vys);
plot(y ~ x);
abline(lm(y~x),col='red');
lm(y~x);
vys$residuals
v = vys$residuals
v2 = v^2
sum(v2);
vys = lm(y ~ 0 + x);
rs = vys$residuals
s = sum(rs^2)
s
vys = lm(y ~ x);
rs = vys$residuals
s = sum(rs^2)
s
#rezidualny sucet stvorcov
#vytvorit priamku pomocou vys
a = vys%coef[1];
a = vys$coef[1];
b = vys$coef[2];
y = a+b*(seq(1,10);
x = c(1,2,3);
y = a+b*x;
plot(y ~ x, type='l');
x = c(1,1.5,2,2,2.5); y = c(3,5,6,6,7);
abline(y ~ x);
line(y ~ x);
lines(y,x);
lines(y,x, col='red');
lines(x,y, col='red');
lines(x ~ y, col='red');
lines(y ~ x, col='red');
y1 = a+b*(c(min(x),max(x)));
plot(y1, col='blue');
plot(y1, x, col='blue', type='l');
plot(y1, x, col='blue', type='line');
plot(y1 ~x , col='blue', type='line');
plot(y1 ~ c(min(x),max(x) , col='blue', type='line');
plot(y1 ~ c(min(x),max(x) , col='blue', type='l');
plot(y1 ~ c(min(x),max(x)) , col='blue', type='l');
points(y,x, col='red')
points(x,y, col='red')
abline(lm(y~x),col='red');
abline(lm(y~0+x),col='green');
y1
#dalsi priklad - prelozit krivku bodmi
x = (45.3,96.5,164.8,260.6,429.1,596.6,775.1)
x = c(45.3,96.5,164.8,260.6,429.1,596.6,775.1)
y = c(8886.09,8643.75,8340.46,8126.6,7486.71,7370.64,7258.11)
plot(x,y)
z1 = 1/x;
v1 = lm(y~z1);
lines(x,v1$fit);
z1 = ln(x);
z1 = log(x);
v2 = lm(y~z2);
z2 = log(x);
v2 = lm(y~z2);
lines(x,v2$fit, col='red');
z3 = 1/exp(x);
v3 = lm(y~z3);
lines(x,v3$fit, col='green');
v3
v3 = lm(y~(-z3));
v3
lines(x,v3$fit, col='green');
y = a(exp(x)^b;
y = a*(exp(x)^b);
y = c(8886.09,8643.75,8340.46,8126.6,7486.71,7370.64,7258.11)
history(1000);