I have built a GAMLSS model to investigate population drivers for a fish species based on an existing dataset, but a problem has arisen when trying to predict response values for a new dataset.
To create a dummy dataset:
Site <- c("Angle Crossing","Angle Crossing Pool","Casuarina Sands","Kambah Pool","Kissops Flat","Lawler Rd","Point Hut Crossing","Retallacks Hole","Scottsdale","Tharwa Sandwash")
Year <- round((rnorm(n=100, mean=2013, sd=2.530846)), digits=0)
LogTurbidity <- (rnorm(n=100, mean=2.026, sd=1.417185))
Datej <- rnorm(n=100, mean=105.0, sd=41.66927)
Catch <- round((rnorm(n=100, mean=1.596, sd=1.895757)), digits=0)
Catch <- ifelse(Catch < 0, 0, Catch)
mc.dummy <- data.frame(Site=Site, Catch=Catch, Year=Year,
Turbidity=LogTurbidity, Datej=Datej)
Using a GAMLSS model:
ZIPGAMM.dummy <- gamlss(Catch ~ cs(Datej, k=5) + cs(Year, k=5) + cs(Turbidity, k=5) + random(Site), family= ZIP(), data=mc.dummy, n.cyc=100)
When I ran the predict()
function on the existing dataset, I was able to obtain all of the model parameters without any issues at all. HOWEVER, when I tried to obtain predicted response values using a new dataset (MC.df.newdata <- data.frame(Datej=c(1:100), Year=2010, Turbidity=1.959954, Site="Retallacks Hole")
), I received the following error message:
MC.predicted <- predict(ZIPGAMM.dummy, newdata = MC.df.newdata, what="mu", type="response")
new prediction
Error in pred.s %*% rep(1, n.smooths) :
requires numeric/complex matrix/vector arguments
In addition: Warning message:
contrasts dropped from factor random(Site)
I used all the same code above without +random(Site)
and everything worked fine, so my question is really how I can get the predict()
function to work with a random effect in the model?