--- title: "kids" author: "Chris Parrish" date: "January 17, 2016" output: pdf_document --- kids Import the data. ```{r} data <- read.csv("Kids198.csv", header=TRUE) head(data) dim(data) ``` Scatterplot matrix. ```{r} pairs(~ Weight + Age + Sex, data=data, col="darkred") ``` Separate linear models for boys and girls ```{r} plot(Weight ~ Age, data=data, pch=16 - 15 * Sex, col="darkred") boys.lm <- lm(Weight[Sex==0] ~ Age[Sex==0], data=data) abline(boys.lm, col="orange", lty=1) # boys girls.lm <- lm(Weight[Sex==1] ~ Age[Sex==1], data=data) abline(girls.lm, col="seagreen4", lty=2) # girls legend(x="topleft", legend=c("boys", "girls"), lty=1:2, col=c("orange", "seagreen4"), inset=0.02) ``` \$\widehat{Weight} =\$ `r round(coef(boys.lm)[1], 3)` + `r round(coef(boys.lm)[2], 3)` \$Age\$ ```{r} coef(boys.lm) ``` \$\widehat{Weight} =\$ `r round(coef(girls.lm)[1], 3)` + `r round(coef(girls.lm)[2], 3)` \$Age\$ ```{r} coef(girls.lm) ``` Multiple regression with interaction. ```{r} kids.lm <- lm(Weight ~ Age * Sex, data=data) options(show.signif.stars=FALSE) summary(kids.lm) ``` For boys: \$\widehat{Weight} =\$ `r round(coef(kids.lm)[1], 3)` + `r round(coef(kids.lm)[2], 3)` \$Age\$ For girls: \$\widehat{Weight} =\$ `r round(coef(kids.lm)[1] + coef(kids.lm)[3], 3)` + `r round(coef(kids.lm)[2] + coef(kids.lm)[4], 3)` \$Age\$ ANOVA. ```{r} anova(kids.lm) ``` Residuals. ```{r} hist(resid(kids.lm), col="wheat") qqnorm(resid(kids.lm), col="orchid") qqline(resid(kids.lm), col="orange") plot(predict(kids.lm), resid(kids.lm), pch=20, col="darkred") abline(h=0, col="orange") ``` CI for a difference of slopes. ```{r} beta3 <- -0.28122 alpha <- 0.05 n <- 198 k <- 3 t.star <- qt(c(alpha/2, 1 - alpha/2), df=n - k - 1) se <- 0.08164 ci <- beta3 + t.star * se ci ```