2

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?

camille
  • 16,432
  • 18
  • 38
  • 60
Monjon
  • 31
  • 4
  • No data, so explanations would be highly speculative. You are asking us to make guesses. – IRTFM Dec 06 '18 at 00:12
  • Thank you for the clarification. Data now included that replicates the error messages. – Monjon Dec 12 '18 at 22:06
  • It is now reproducible. I get the same error, even with some minor modifications and the inclusion of a data argument. – IRTFM Dec 13 '18 at 15:26
  • I did a google search as well and the only exact match to that error from predict.gamlss was a russion site that apparently automatically translates SO questions into Russian, your question in this instance. Interesting. http://qaru.site/questions/16688726/gamlss-error-predicting-fitted-values-from-new-dataset – IRTFM Dec 13 '18 at 16:09
  • Thanks @42-, will be interesting to see how the russian site goes. I have also contacted GAMLSS directly, and will provide an update based on the response. – Monjon Dec 18 '18 at 00:39

0 Answers0