What is it?
Multilevel Examples:
lm.mass <- lm(fat.percent ~ log(mass.female),
data = milk3)
summary(lm.mass)
##
## Call:
## lm(formula = fat.percent ~ log(mass.female), data = milk3)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.34 -4.18 -1.05 1.22 15.74
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 20.515 3.249 6.31 1.7e-07 ***
## log(mass.female) -1.752 0.457 -3.83 0.00044 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.96 on 40 degrees of freedom
## Multiple R-squared: 0.268, Adjusted R-squared: 0.25
## F-statistic: 14.7 on 1 and 40 DF, p-value: 0.000443
We’ll unpack what each of these is
par(mfrow = c(1,2), mar = c(5,2,7,0.25))
arm::coefplot(lm.mass,intercept = T,
mar=c(5,6,8,1),
cex.pts = 2,
col.pts = 1:2,
pch.pts = 16:17,
lwd = 3)
mtext(text = "y = m*x + b",
side = 1,adj= 1, line = -2)
mtext(text = "fat = slope*log(mass) + intercept",side = 1,adj= 1, line = -1)
make.plot()
y. <- coef(lm.mass)[1]
abline(v = 0, col = 2,lwd = 2)
arrows(x0 = 1,x1=0,
col = 2,lwd = 2,
y0 = y.)
lab. <- round(coef(lm.mass)[1],2)
text(x = 1.71,y = y.,
label = lab.)
lm.null <- lm(fat.percent ~ 1,
data = milk3)
lm.mass <- lm(fat.percent ~ log(mass.female),
data = milk3)
The mean fat value is 8.6
summary(milk3[,"fat.percent"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.70 3.75 6.60 8.58 11.90 27.00
#NOTE: order w/in anova() doesn't matter
anova(lm.null,
lm.mass)
## Analysis of Variance Table
##
## Model 1: fat.percent ~ 1
## Model 2: fat.percent ~ log(mass.female)
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 41 1943
## 2 40 1422 1 521 14.7 0.00044 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
AIC(lm.null,
lm.mass)
## df AIC
## lm.null 2 284
## lm.mass 3 273
library(bbmle)
AICtab(lm.null,
lm.mass,
base = T)
## AIC dAIC df
## lm.mass 273.1 0.0 3
## lm.null 284.2 11.1 2
library(bbmle)
ICtab(lm.null,
lm.mass,
type = c("AICc"),
base = T)
## AICc dAICc df
## lm.mass 273.7 0.0 3
## lm.null 284.5 10.8 2