Rasmus Bååth
02/04/2014
xyplot i R.head(d)
country continent lifeExp gdpPercap
12 Afghanistan Asia 43.83 974.6
24 Albania Europe 76.42 5937.0
36 Algeria Africa 72.30 6223.4
48 Angola Africa 42.73 4797.2
60 Argentina Americas 75.32 12779.4
84 Austria Europe 79.83 36126.5
lifeExp ~ 1
ingen explonatory-variabel
densityplot(~ lifeExp, data=d)
lifeExp ~ gdpPercap
kategorisk explanatory-variable
xyplot(lifeExp ~ continent, data=d)
lifeExp ~ gdpPercap
kvantitativ explanatory-variable
xyplot(lifeExp ~ gdpPercap, data=d)
lifeExp ~ gdpPercap + continent
kvantitativ + kategorisk explanatory-variable.
Med group = ...
xyplot(lifeExp ~ gdpPercap, group=continent, auto.key=TRUE, data=d)
lifeExp ~ gdpPercap + continent
kvantitativ + kategorisk explanatory-variable.
Med |
xyplot(lifeExp ~ gdpPercap | continent, data=d)
\[ \]
\[ \]
\[ \] \[ y = a + b * x \]
\[ \]
\[ \]
\[ \] \[ y = a + b * x \]
lm i R: lm( y ~ 1 + x, data=d)y = a * 1 + b * xlm(time ~ 1, data=swim)
Call:
lm(formula = time ~ 1, data = swim)
Coefficients:
(Intercept)
59.9
lm(time ~ year, data=swim)
Call:
lm(formula = time ~ year, data = swim)
Coefficients:
(Intercept) year
567.24 -0.26
lm(time ~ sex, data=swim)
Call:
lm(formula = time ~ sex, data = swim)
Coefficients:
(Intercept) sexM
65.2 -10.5
time ~ 1 + sexlifeExp ~ 1 + continentlm(time ~ year + sex, data=swim)
Call:
lm(formula = time ~ year + sex, data = swim)
Coefficients:
(Intercept) year sexM
555.717 -0.251 -9.798
lm(time ~ year + sex + year:sex, data=swim)
Call:
lm(formula = time ~ year + sex + year:sex, data = swim)
Coefficients:
(Intercept) year sexM year:sexM
697.301 -0.324 -302.464 0.150
y ~ 1 + x * cat (men tydligare att skriva ut hela)
model1 <- lm(iq ~ rhythm, data=a_relation)
model1
Call:
lm(formula = iq ~ rhythm, data = a_relation)
Coefficients:
(Intercept) rhythm
78.084 0.438
confint(model1)
2.5 % 97.5 %
(Intercept) 74.7149 81.4537
rhythm 0.3713 0.5054
model2 <- lm(iq ~ length, data=no_relation)
model2
Call:
lm(formula = iq ~ length, data = no_relation)
Coefficients:
(Intercept) length
101.8525 -0.0131
confint(model2)
2.5 % 97.5 %
(Intercept) 93.19284 110.51210
length -0.06395 0.03774