Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Answers for MA6521 2019 Exam

Note there is often more than one possible answer to each question. The answers are illustrative examples. All sensible answers that answer the questions requirements will receive the marks.

1a) Answered using SPSS, but also possible to use R.

Mann Whitney U Test for whether gender effects answer:

H0: The distribution of question is the same across both genders.

H1: The distribution of question is different for males and females.

 

As we do not reject the null hypothesis (with p-value 0.418) there is no evidence that whether the customer is male or female affects the response to the question.

Mann Whitney U Test for whether having children in the party affects the answer:

H0: The distribution of question is the same regardless of whether the customer has children or not.  H1: The distribution of question is different depending on whether the customer has children or not.

 

Again as we do not reject the null hypothesis (with p-value 0.153) there is no evidence that whether the customer had children in the party affects the response to the question.

Kruskal-Wallis Test for whether the accommodation type has an effect:

H0: The distribution of question is the same regardless of which level of accommodation stayed in. H1: The distribution of question depends on the accommodation stayed in.

 

We reject the null hypothesis (with p-value < 0.001), so there is significant evidence that there is a difference              between the different accommodation types. We note that you cannot conclude where the difference lies from this test and would need either look a further test, compare medians or examine a graph such as:


 

This shows bronze accommodation (labelled b) has more customers with responses of disagree (2) or strongly disagree (1), than silver or gold accommodation. Whereas silver or gold accommodation has more customers with responses of agree (4) or strongly agree (5) than bronze.

b)

This report is about Pi-Cove Park questionnaire responses to the statement Overall I am happy with my stay at Pi- Cove Park.

There is no evidence in the data that the gender nor whether the customer’s party included children affects the     outcome of the question. However, there is evidence in the data that the type of accommodation affects the          outcome of the question. This is illustrated by the figure below, where it is clear bronze accommodation has more customers with responses of disagree or strongly disagree, than silver or gold accommodation. Whereas silver or   gold accommodation has more customers with responses of agree or strongly agree than bronze.

In conclusion bronze accommodation appears to cause more dissatisfaction amongst customers.

 

 

 

Does accomodation type effect overall stay

Strongly         Disagree          Neither            Agree            Strongly

Disagree                                Agree not                                   Agree

Disagree

Reponse to question:

Overall I am happy with my stay at Pi-Cove park

 


2)

Fit a Binomial GLM as number ofchicks is an integer with an upper limit of eggs.

Species is a factor and Year is better as a factor (but could be treated as a continuous covariate if only interested in an increase/decrease over years), temp is a continuous covariate and nest is a random effect.

First consider all variables except random effect:

R code to open data set:

> examdata <- read_excel("exam2019.xlsx",sheet=2)

> head(examdata)

 

R code to fit the full model (without random nest effect).

> modelyts<-glm(cbind(chicks,(eggs-chicks))~ factor(year)+temp+factor(species),data=ex  

 

R code to fit the other combinations of models

> modely <- glm(cbind(chicks,(eggs-chicks))~ factor(year),data=examdata,family = binom  

 

ial())

> modelt <-

> models <-

nomial())

glm(cbind(chicks,(eggs-chicks))~ temp,data=examdata,family = binomial())

glm(cbind(chicks,(eggs-chicks))~ factor(species),data=examdata,family = bi

 


 

> modelyt <- glm(cbind(chicks,(eggs-chicks))~

binomial())

> modelys <- glm(cbind(chicks,(eggs-chicks))~

ta,family = binomial())

> modelts <- glm(cbind(chicks,(eggs-chicks))~

y = binomial())

factor(year)+temp,data=examdata,family =

 

factor(year)+factor(species),data=examda

 

temp+factor(species),data=examdata,famil

Model selection GLMs AIC:

The best model, the one with the smallest AIC, includes both temperature and species, but not year. The model weight is 0.97, so there is one best model.

R code for model selection analysis of deviance.

> modelconst <- glm(cbind(chicks,(eggs-chicks))~ 1,data=examdata,family = binomial())

> Modellist <- list( )

> Modellist[[1]] <- modely

> Modellist[[2]] <- modelt

> Modellist[[3]] <- models

> modelcompare <- modelconst

> modelname <- c("year", "temp", "species")

> dev <- rep(0,(length(Modellist)))

> for (i in 1:(length(Modellist))){dev[i]=Modellist[[i]]$deviance}

> devcompare <- modelcompare$deviance

> DF <- rep(0,(length(Modellist)))

> for (i in 1:(length(Modellist))){DF[i]=Modellist[[i]]$df.residual}

> DFcompare <- modelcompare$df.residual

> diffdev=devcompare-dev

> diffDF=DFcompare-DF

> pval=pchisq(diffdev, df=diffDF, lower.tail=FALSE)

> devtable = data.frame(modelname,diffdev,diffDF,pval)


At level 1 (comparing to constant model) both temperature and species have a significant improvement to the deviance ofthe model. Species has highest p-value, so we compare to this model at the next level. At level 2 (comparing to         species) only adding temp is significant. So compare to species+temp at next level. At level 3 adding year is not            significant. Therefore the best model is species+temp

Both AIC and analysis of deviance select the best model as species+temp


R code for fitting temp + species + nest random effect

> modeltsn <- glmer(cbind(chicks,(eggs-chicks))~ temp+factor(species)+(1|nest),data=ex  

The AIC for the model with random effects is 205.8, compared with an AIC of 234.95 for the same model without random effects. So the best model has temperature and species and a random effect.

> LRT <- 2*(logLik(modeltsn)[1]-logLik(modelts)[1])

> pvalue <- 1-pchisq(LRT, df=1)

> LRTresults <- data.frame(LRT,pvalue)

> print(LRTresults)

LRT       pvalue

1 31.15208 2.385836e-08

The p-value of <0.0001 suggests that we should include the random effect


2c

The best model includes the covariate temperature, the factor species and the random effect nest. The parameter estimates and standard errors for this model are as follows:

Parameter       Estimate       SE          

Intercept         -3.55             0.95

 


Temp       Species 2 Species 3 Nest RE


0.22

1.57

2.11

1.47


0.056

1.00

0.99


The productivity rate (proportion of chicks per egg) increases slightly with temperature. Species 2 has the highest   productivity rate, then species 3 and species 1 has the smallest productivity rate. However, species 3 is not              significantly different from species 1. Whereas species 2 is significantly different from species 1. The random nest effect has a variance of 1.47.