## Settings for RMarkdown http://yihui.name/knitr/options#chunk_options
opts_chunk$set(comment = "", warning = FALSE, message = FALSE, tidy = FALSE,
echo = T, fig.width = 10, fig.height = 8)
options(width = 125, scipen = 5, digits = 5)
setwd("~/statistics/bio213/")
library(gdata)
lbw <- read.xls("~/statistics/bio213/lbw.xls")
lbw$smoke <- factor(lbw$smoke, levels = 0:1, labels = c("non-smoker","smoker"))
## Same data available online: http://www.umass.edu/statdata/statdata/data/index.html
## Cases 10 and 39 needs fix to make them identical to Dr. Orav's dataset
## lbw2 <- read.xls("http://www.umass.edu/statdata/statdata/data/lowbwt.xls")
## lbw2[c(10,39),"BWT"] <- c(2655,3035)
model.smoke.lwt.interaction <- lm(bwt ~ smoke + lwt + smoke:lwt, lbw)
summary(model.smoke.lwt.interaction)
Call:
lm(formula = bwt ~ smoke + lwt + smoke:lwt, data = lbw)
Residuals:
Min 1Q Median 3Q Max
-2040.3 -456.2 28.6 531.7 1977.7
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2347.51 312.72 7.51 2.5e-12 ***
smokesmoker 43.90 451.16 0.10 0.923
lwt 5.40 2.34 2.31 0.022 *
smokesmoker:lwt -2.42 3.39 -0.71 0.476
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 709 on 185 degrees of freedom
Multiple R-squared: 0.07, Adjusted R-squared: 0.055
F-statistic: 4.64 on 3 and 185 DF, p-value: 0.00372
library(effects)
plot(effect("smoke:lwt", model.smoke.lwt.interaction), multiline = TRUE)