1 Regression Homework Solutions EPP 245/298 Statistical Analysis of Laboratory Data
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 2 Exercise 5.1 > library(ISwR) > data(rmr) > attach(rmr) > names(rmr) [1] "body.weight" "metabolic.rate" > plot(body.weight,metabolic.rate) > rmr.lm <- lm(metabolic.rate ~ body.weight) > abline(coef(rmr.lm),col="red",lwd=2)
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 3
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 4 > coef(rmr.lm) (Intercept) body.weight > *70 [1] > sum(coef(rmr.lm)*c(1,70)) [1] > predict(rmr.lm,data.frame(body.weight=70)) [1]
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 5 > summary(rmr.lm) Call: lm(formula = metabolic.rate ~ body.weight) Residuals: Min 1Q Median 3Q Max Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) e-13 *** body.weight e-09 *** --- Signif. codes: 0 `***' `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 Residual standard error: on 42 degrees of freedom Multiple R-Squared: , Adjusted R-squared: F-statistic: on 1 and 42 DF, p-value: 7.025e-09
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 6 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) e-13 *** body.weight e-09 *** > * [1] > * [1] > tmp <- summary(rmr.lm) > names(tmp) [1] "call" "terms" "residuals" "coefficients" [5] "aliased" "sigma" "df" "r.squared" [9] "adj.r.squared" "fstatistic" "cov.unscaled" > tmp$coef Estimate Std. Error t value Pr(>|t|) (Intercept) e-13 body.weight e-09 > class(tmp$coef) [1] "matrix" > dim(tmp$coef) [1] 2 4
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 7 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) e-13 *** body.weight e-09 *** > * [1] > * [1] > tmp$coef[2,1] *tmp$coef[2,2] [1] > tmp$coef[2,1] *tmp$coef[2,2] [1]
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 8 Exercise 5.2 > data(juul) > names(juul) [1] "age" "menarche" "sex" "igf1" "tanner" "testvol" > attach(juul) > juul.lm 25)) > summary(juul.lm) Call: lm(formula = sqrt(igf1) ~ age, subset = (age > 25)) Residuals: Min 1Q Median 3Q Max Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) <2e-16 *** age <2e-16 *** --- Signif. codes: 0 `***' `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 Residual standard error: on 120 degrees of freedom Multiple R-Squared: 0.446, Adjusted R-squared: F-statistic: 96.6 on 1 and 120 DF, p-value: < 2.2e-16
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 9
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 10 > plot(age,igf1) > plot(age[age>25],igf1[age>25]) > abline(coef(lm(igf1 ~ age,sub=(age>25))),col="red",lwd=2) > plot(age[age>25],sqrt(igf1)[age>25]) > abline(coef(juul.lm),col="red",lwd=2)
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 11
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 12
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 13
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 14
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 15 > data(malaria)> > names(malaria) [1] "subject" "age" "ab" "mal" > attach(malaria) > hist(ab) > hist(log(ab)) > plot(age,log(ab)) > summary(lm(log(ab) ~ age)) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) <2e-16 *** age * --- Signif. codes: 0 `***' `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 Residual standard error: on 98 degrees of freedom Multiple R-Squared: , Adjusted R-squared: F-statistic: on 1 and 98 DF, p-value: Exercise 5.3
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 16
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 17
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 18
October 27, 2004EPP 245 Statistical Analysis of Laboratory Data 19