Reputation: 11
I'm trying to fit a model in R which shows how depth and sediment type influence seagrass density (response) and collected a dataframe with about 5000 rows. For ease of data collection, we have discrete values of seagrass density set in 5 categories, from 1 to 5 (each representing a band of percent coverage). There are no NA values in the data frame. There will be spatial autocorrelation in the data so I added a smooth term with the latitude and longitude to account for this.
I'm using the OCAT family with a logit link to account for the ordinal type data and set theta to 4 (since there are 4 "steps" between the discrete values of density). Let me know if any of this is incorrect.
Here is my model:
model_gam_spatial <- gam(Density ~ s(Latitude, Longitude) + Depth + Substrate.type,
data = seagrass_clean, family = ocat(theta = 4, link = "logit"))
I keep getting this error message when I try to run the model
"Error in eval(family$initialize) : values out of range"
Can any suggest what I'm doing wrong? Or any other tips? If there is a better kind of model which would be suitable for my data also please let me know. Any help with this would be much appreciated.
Upvotes: 1
Views: 64
Reputation: 11
Update: After amending the model to include R = 5 and theta = NULL, I was still getting an error message. The solution is that you cannot use the logit link function in the OCAT family. This model below worked for me:
model_gam_spatial <- gam(Density ~ s(Latitude, Longitude) + Substrate.type + Depth, data = seagrass_present, family = ocat(R=4))
Upvotes: 0
Reputation: 174778
You need to set ocat()
's argument R
to the number of groups in your response, to 5 in your case as you have 5 groups. theta
needs to be a vector of length R-2
cut points on the latent variable, if you supply it. If you leave it at the default (NULL
), mgcv will estimate the R-2
cut points for you, which is typically what you want to have happen.
Upvotes: 1