4 Main Effects Model (3 points)
#install.packages("HistData", repos = "http://cran.us.r-project.org", dependencies=TRUE). (After the first compile, we may comment out this line.
library("HistData")
data(GaltonFamilies)
Galton2 <- data.frame(GaltonFamilies)
names(Galton2)
## [1] "family" "father" "mother" "midparentHeight"
## [5] "children" "childNum" "gender" "childHeight"
Note: I will use “we” or “us” hereinafter to avoid first paragraph narrative which in my opinion does not come across as a very convincing means of communicating data analysis. In other words, the use of “we” or “us” does not indicate that another individual or entity assisted in the response to the six Mid-Term Exam responses.
4.1. Fit the main effects model g2: childHeight ~ gender + midparentHeight.
g2 <- lm(childHeight~gender+midparentHeight, data = Galton2)
Response to Question No. 4.1: As shown above, we use the R function lm to create interaction model “g2” which is used to carry out regression at a single stratum analysis of variance and analysis of co-variance.
4.2. Obtain the coefficients, standard error of estimate, t-value of estimate, and p-value of estimate for model g2.
## install.packages("HistData", repos = "http://cran.us.r-project.org", dependencies=TRUE). (After the first compile, we may comment out this line.
library("HistData")
data(GaltonFamilies)
Galton2 <- data.frame(GaltonFamilies)
names(Galton2)
## [1] "family" "father" "mother" "midparentHeight"
## [5] "children" "childNum" "gender" "childHeight"
Response to Question No. 4.2: As shown above, the variables are displayed.
summary(g2)$coef
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 16.5141022 2.73391750 6.040454 2.219169e-09
## gendermale 5.2151054 0.14215811 36.685247 5.519341e-183
## midparentHeight 0.6870152 0.03943983 17.419326 4.881957e-59
4.3. Interpret the value of the coefficient for gender.
Response to Question No. 4.3: As shown in the output data above, males in are 5.2 inches taller than females controlling for the average weight of their parents (i.e., “midparentHeight”) according to data collected by Sir Francis Galton in the 19th Century and supporting his theory that height is hereditary.