This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(wooldridge)
data("bwght")
df <- bwght
##QUESTION 4i
intercept <- 119.77
slope <- -0.514
cigs_0 <- 0
bwght_0 <- intercept + slope * cigs_0
cigs_20 <- 20
bwght_20 <- intercept + slope * cigs_20
bwght_0
## [1] 119.77
bwght_20
## [1] 109.49
difference <- bwght_0 - bwght_20
difference
## [1] 10.28
Babies whose mothers smoke 20 cigarettes per day weigh 10.28oz less than babies whose mothers who smoke 0 cigarettes per day
Not necessarily because there may also be other factors affecting the mothers that affect the birth weight of the babies that are not accounted for
To predict a birth weight of 125 ounces, the “cigs” variable would have to be a negative number. There is no possible way to smoke a negative amount of cigarettes.
“cigs” would have to be equal to = -10.175
range_bwght <- range(df$bwght, na.rm = TRUE)
range_bwght
## [1] 23 271
No. This doesn’t change anything because of the 85% of non-smoking mothers (total of 1180), the babies weights still vary below and above 125.
data("sleep75")
dg <- "sleep75"
m1 <- lm(sleep ~ totwrk, data = sleep75)
summary(m1)
##
## Call:
## lm(formula = sleep ~ totwrk, data = sleep75)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2429.94 -240.25 4.91 250.53 1339.72
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3586.37695 38.91243 92.165 <2e-16 ***
## totwrk -0.15075 0.01674 -9.005 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 421.1 on 704 degrees of freedom
## Multiple R-squared: 0.1033, Adjusted R-squared: 0.102
## F-statistic: 81.09 on 1 and 704 DF, p-value: < 2.2e-16
coef(m1)
## (Intercept) totwrk
## 3586.3769515 -0.1507458
nobs(m1)
## [1] 706
summary(m1)$r.squared
## [1] 0.1032874
b1 <- coef(m1)["totwrk"]
change_sleep <- b1 * 120
change_sleep
## totwrk
## -18.0895
data("charity")
mean(charity$gift)
## [1] 7.44447
mean(charity$gift == 0) * 100
## [1] 60.00469
mean(charity$mailsyear)
## [1] 2.049555
summary(charity$mailsyear)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.25 1.75 2.00 2.05 2.50 3.50