2. Poisson 🐟

Likelihood = Π e^(-λ) * λ^x / x! = e^(-15λ) * λ^(Σx) / Π(x!)
l = -15λ + Σx ln(λ) - Σln(x!)
l’ = -15 + Σx / λ = 0 => λ = 6+6/9

#Potential lambda values
lambdaValues <- 1:90
lambdaValues <- lambdaValues/3
lambdaHat <- 6 + 6/9
#Log Likelihoods with every 5th point plotted
#and the maximum likelihood estimate point plotted in blue
llls <- 100*log(lambdaValues) - 15*lambdaValues
plot(lambdaValues[c(F, T, F, F, F)], llls[c(F, T, F, F, F)])
lines(lambdaValues, llls)
points(lambdaHat, 100*log(lambdaHat) - 15*lambdaHat, col = "blue", pch = 18)

###3. Swiss 🇨🇭

What’s the best thing about Switzerland? Well, the flag is a big plus.

Build the models:

babyDeathModel1 <- lm(Infant.Mortality ~ Catholic + Education + Examination + Fertility + Agriculture, data = swiss)
babyDeathModel2 <- lm(Infant.Mortality ~ Catholic + Education + Examination + Fertility, data = swiss)

Perform a likelihood ratio test.

#test statistic
lts <- -2*(logLik(babyDeathModel2)-logLik(babyDeathModel1))
#chi-sq table
pval <- dchisq(lts[1], df = 1)

The p-value, 0.8079358, is not significant with df = 1.

Perform a Wald test.

#Retrieve standard errors and coefficients
se <- sqrt(diag(vcov(babyDeathModel1)))
coef <- coef(babyDeathModel1)
#Calculate test statistics
ts <- coef[6]/se[6]
pval <- 2*pt(ts[1], df = 47 - (1+5))

The p-value, 0.6782676, is not significant.

Perform an anova test.

pval <- anova(babyDeathModel1, babyDeathModel2)[6][[1]]

The p-value, 0.6782676, is not significant.

Calculate AIC and BIC.

aic <- AIC(babyDeathModel1) - AIC(babyDeathModel2)
bic <- BIC(babyDeathModel1) - BIC(babyDeathModel2)

The difference of AIC between the two models, 1.8003154, is less than 10.
The difference of BIC between the two models, 3.650463, is less than 10.

Agriculture is not helpful for modeling the death rate of babies.