Error in predict function (Matrices must have same number of rows in cbind2(.Call(dense_to_Csparse, x), y))

277 views
Skip to first unread message

Bérénice Givord-Coupeau

unread,
Jul 6, 2021, 1:19:37 PM7/6/21
to unmarked

Hi everyone,

I'm working on a site-occupancy study. The model selected by unmarked is as following :

mod12 <- occu(~ temperature ~ bush_coverage, data)

Everything works fine when I'm trying to predict and plot data according to siteCovs (bush_coverage) :

nd_cov <- data.frame(bush_coverage = seq(min(site.covs$bush_coverage), max(site.covs$bush_coverage), lenght = 50)) N_pred_cov <- predict(mod12, type = 'state', newdata = nd_cov) plot(nd_cov$bush_coverage, N_pred_cov[,1], colonne) type = "l", lwd = 3, xlab = "Percentage bush coverage", ylab = "Occupancy probability")

But when I'm trying to predict detection probability and plot data according to temperature I'm facing a problem :

nd_temp <- data.frame (temp = seq(3,21, by = 0.45)) N_pred_temp <- predict(mod12, type = 'det', newdata = nd_temp) 
 Error: Matrices must have same number of rows in cbind2(.Call(dense_to_Csparse, x), y)

I created a gradient to predict detection in order to get rid of NA values in my obsCovs data frame and nd_temp has the same number of rows as my data. When I'm changing the size of nd_temp I'm only getting a warning, so I'm assuming this gradient size is not the issue here :

'newdata' had 181 rows but variables have 41 rows

I'm sorry if it's a naive question but I can't find where the issue comes from.

Thank you a lot in advance for your help !

Ken Kellner

unread,
Jul 6, 2021, 1:38:48 PM7/6/21
to unmarked
Try changing

nd_temp <- data.frame (temp = seq(3,21, by = 0.45))

to 

nd_temp <- data.frame (temperature = seq(3,21, by = 0.45))

Ken

Reply all
Reply to author
Forward
0 new messages