Example 11.1 Obstetricians sometimes order tests for es- triol levels from 24-hour urine specimens taken from preg- nant women who are near term, because level of estriol has been found to be related to infant birthweight. The test can provide indirect evidence of an abnormally small fetus. The relationship between estriol level and birthweight can be quantified by fitting a regression line that relates the two variables. Data is given in Table 11.1 on page 429.
Please finish the R code to conduct the hypothesis testing. I need the code for the p-value for the F test, tstat, and the p value for tstat. Write the conclusion to the hypothesis testing once completed.
# Example 11.1
# simple linear regression
# H0: B=0 (there is no
# H1: B≠0 (there is a linear correlation)
data <- data.frame(estriol=c(7,9,9,12,14,16,16,14,16,16,17,19,21,24,15,16,17,25,27,15,15,15,16,19,18,17,18,20,22,25,24),
birthweight=c(25,25,25,27,27,27,24,30,30,31,30,31,30,28,32,32,32,32,34,34,34,35,35,34,35,36,37,38,40,39,43))
linear <- lm(birthweight~estriol, data = data)
summary(linear)
# This gives the results for a and b and the F statistic.
# Call:
# lm(formula = birthweight ~ estriol, data = data)
#
# Residuals:
# Min 1Q
# -8.1200 -2.0381 -0.0381 3.3537 6.8800
#
# Coefficients:
# Estimate Std. Error t value Pr(>|t|)
# (Intercept) 21.5234 2.6204 8.214 4.68e-09 ***
# estriol 0.6082 0.1468 4.143 0.000271 ***
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
# Residual standard error: 3.821 on 29 degrees of freedom
# Multiple R-squared: 0.3718, Adjusted R-squared: 0.3501
# F-statistic: 17.16 on 1 and 29 DF, p-value: 0.0002712
xbar <-
ybar <- mean(data$birthweight)
Lxx <- sum((data$estriol - xbar)^2)
Lxx
# 677.4194
Lxy <- sum((data$estriol - xbar)*(data$birthweight - ybar))
Lxy
# 412
b <- Lxy/Lxx
b
# 0.6081905
a <- ybar - b*xbar
a
# 21.52343
yhat <- a + b*data$estriol
totalSS <- sum((data$birthweight - ybar)^2)
totalSS
# 674
#250.5745 + 423.4255
regSS <- sum((yhat-ybar)^2)
regSS
# 250.5745
resSS <- sum((data$birthweight - yhat)^2)
resSS
# 423.4255
k <- 1
n <- 31
regMS <- regSS/k
regMS
# 250.5745
resMS <- resSS/(n-k-1)
resMS
# 14.60088
Fstat <- regMS/resMS
Fstat
# 17.1616
summary(aov(linear))
# Df Sum Sq Mean Sq F value Pr(>F)
# estriol 1 250.6 250.6 17.16 0.000271 ***
# Residuals 29 423.4 14.6
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Step by step
Solved in 2 steps with 1 images