+ All Categories
Home > Documents > Regression Homework Solutions

Regression Homework Solutions

Date post: 09-Jan-2016
Category:
Upload: gizi
View: 32 times
Download: 0 times
Share this document with a friend
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
19
1 Regression Homework Solutions EPP 245/298 Statistical Analysis of Laboratory Data
Transcript
Page 1: Regression Homework Solutions

1

Regression Homework Solutions

EPP 245/298

Statistical Analysis of

Laboratory Data

Page 2: Regression Homework Solutions

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)

Page 3: Regression Homework Solutions

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

3

Page 4: Regression Homework Solutions

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

Page 5: Regression Homework Solutions

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

Page 6: Regression Homework Solutions

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

Page 7: Regression Homework Solutions

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

Page 8: Regression Homework Solutions

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

Page 9: Regression Homework Solutions

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

9

Page 10: Regression Homework Solutions

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)

Page 11: Regression Homework Solutions

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

11

Page 12: Regression Homework Solutions

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

12

Page 13: Regression Homework Solutions

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

13

Page 14: Regression Homework Solutions

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

14

Page 15: Regression Homework Solutions

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

Page 16: Regression Homework Solutions

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

16

Page 17: Regression Homework Solutions

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

17

Page 18: Regression Homework Solutions

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

18

Page 19: Regression Homework Solutions

October 27, 2004 EPP 245 Statistical Analysis of Laboratory Data

19


Recommended