HiThis assignment as no word limit.

1 answer below »
HiThis assignment as no word limit.

Answered Same DayMay 09, 2021STA5ARMLa Trobe University

Answer To: HiThis assignment as no word limit.

Abr Writing answered on May 14 2021
146 Votes
Assignment 3
Assignment 3
STA5ARM
14/05/2019
Loading the data into R workspace
birth.weight <- read.csv("Birthweight.csv")
birth.weight$S <- as.factor(birth.weight$S)
summary(birth.weight)
Mother BW S
Min. : 14 Min. : 284 0:7400
1st Qu.
: 16090 1st Qu.:3147 1:1204
Median : 33339 Median :3486
Mean : 35934 Mean :3470
3rd Qu.: 52179 3rd Qu.:3799
Max. :109039 Max. :5642
Where,
• Mother : This is a factor variable that identifies the mother.
• BW : The birth weight (in grams) of a new born child.
• S : This is a fixed factor that identifies the smoking status of the mother during pregnancy. It has two
levels (0 = non smoker, 1 = smoker).
1. Creating the predictors for the correlated random effects model
Part 1.
birth.weight %>%
group_by(Mother) %>%
summarise(
SMean = mean(as.numeric(S) - 1)
) -> SMean
summary(SMean$SMean)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.0000 0.0000 0.0000 0.1425 0.0000 1.0000
child.id <- c()
mothers <- c()
for (i in 1:nrow(birth.weight)){
child.id <- c(child.id,
sum(birth.weight$Mother[i] == mothers)+1)
mothers <- c(mothers, birth.weight$Mother[i])
}
birth.weight.dt <- setDT(birth.weight)
summary(dcast(birth.weight.dt,
Mother~child.id,value.var='S'))
Mother 1 2 3
1
Min. : 14 0:3417 0:3406 0 : 577
1st Qu.: 16074 1: 561 1: 572 1 : 71
Median : 33273 NA's:3330
Mean : 35879
3rd Qu.: 52197
Max. :109039
birth.weight <- merge(birth.weight,
SMean,
by = "Mother")
birth.weight$SDiff <- as.numeric(birth.weight$S) -
1 -
birth.weight$SMean
summary(birth.weight)
Mother BW S SMean
Min. : 14 Min. : 284 0:7400 Min. :0.0000
1st Qu.: 16090 1st Qu.:3147 1:1204 1st Qu.:0.0000
Median : 33339 Median :3486 Median :0.0000
Mean : 35934 Mean :3470 Mean :0.1399
3rd Qu.: 52179 3rd Qu.:3799 3rd Qu.:0.0000
Max. :109039 Max. :5642 Max. :1.0000
SDiff
Min. :-0.6667
1st Qu.: 0.0000
Median : 0.0000
Mean : 0.0000
3rd Qu.: 0.0000
Max. : 0.6667
2. Testing the endogeneity parameter
Part 2.
Notice the grammar in the lmer function that defines the model: the term (1|Mother) is added to the model
to indicate that Mother is the random term.
As a technical note, the 1 indicates that an intercept is to be fitted for each level of the random variable.
As another technical note, REML stands for restricted maximum likelihood. It is a method of fitting the
model, and is often considered better than fitting with a conventional ML (maximum likelihood) method.
model <- lmer(BW ~ 1 +...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here