Regression Homework Solutions

Preview:

DESCRIPTION

Regression Homework Solutions. EPP 245/298 Statistical Analysis of Laboratory Data. Exercise 5.1. > library(ISwR) > data(rmr) > attach(rmr) > names(rmr) [1] "body.weight" "metabolic.rate" > plot(body.weight,metabolic.rate) > rmr.lm

Citation preview

1

Regression Homework Solutions

EPP 245/298

Statistical Analysis of

Laboratory Data

October 27, 2004 EPP 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, 2004 EPP 245 Statistical Analysis of Laboratory Data

3

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

4

> coef(rmr.lm)(Intercept) body.weight 811.226674 7.059528 > 811.226674 + 7.059528*70[1] 1305.394> sum(coef(rmr.lm)*c(1,70))[1] 1305.394> predict(rmr.lm,data.frame(body.weight=70))[1] 1305.394

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

5

> summary(rmr.lm)

Call:lm(formula = metabolic.rate ~ body.weight)

Residuals: Min 1Q Median 3Q Max -245.74 -113.99 -32.05 104.96 484.81

Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 811.2267 76.9755 10.539 2.29e-13 ***body.weight 7.0595 0.9776 7.221 7.03e-09 ***---Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1

Residual standard error: 157.9 on 42 degrees of freedomMultiple R-Squared: 0.5539, Adjusted R-squared: 0.5433 F-statistic: 52.15 on 1 and 42 DF, p-value: 7.025e-09

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

6

Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 811.2267 76.9755 10.539 2.29e-13 ***body.weight 7.0595 0.9776 7.221 7.03e-09 ***

> 7.0595 - 1.96*0.9776[1] 5.143404> 7.0595 + 1.96*0.9776[1] 8.975596> 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) 811.226674 76.9755034 10.53876 2.288384e-13body.weight 7.059528 0.9775978 7.22130 7.025380e-09> class(tmp$coef)[1] "matrix"> dim(tmp$coef)[1] 2 4

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

7

Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 811.2267 76.9755 10.539 2.29e-13 ***body.weight 7.0595 0.9776 7.221 7.03e-09 ***

> 7.0595 - 1.96*0.9776[1] 5.143404> 7.0595 + 1.96*0.9776[1] 8.975596> tmp$coef[2,1] - 1.96*tmp$coef[2,2][1] 5.143436> tmp$coef[2,1] + 1.96*tmp$coef[2,2][1] 8.97562

October 27, 2004 EPP 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 <- lm(sqrt(igf1) ~ age, sub=(age>25))> summary(juul.lm)

Call:lm(formula = sqrt(igf1) ~ age, subset = (age > 25))

Residuals: Min 1Q Median 3Q Max -4.8642 -1.1661 0.1018 0.9450 4.1136

Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 18.71025 0.49462 37.828 <2e-16 ***age -0.10533 0.01072 -9.829 <2e-16 ***---Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1

Residual standard error: 1.741 on 120 degrees of freedomMultiple R-Squared: 0.446, Adjusted R-squared: 0.4414 F-statistic: 96.6 on 1 and 120 DF, p-value: < 2.2e-16

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

9

October 27, 2004 EPP 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, 2004 EPP 245 Statistical Analysis of Laboratory Data

11

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

12

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

13

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

14

October 27, 2004 EPP 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) 3.83697 0.38021 10.092 <2e-16 ***age 0.10350 0.03954 2.618 0.0103 * ---Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1

Residual standard error: 1.478 on 98 degrees of freedomMultiple R-Squared: 0.06536, Adjusted R-squared: 0.05582 F-statistic: 6.853 on 1 and 98 DF, p-value: 0.01025

Exercise 5.3

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

16

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

17

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

18

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

19