Understanding t.cols in predict.stPGOcc and predict.svcPGOcc

12 views
Skip to first unread message

Sara Williams

unread,
Jul 22, 2026, 7:06:50 PM (9 days ago) Jul 22
to spOccupancy and spAbundance users
Hello Jeff and listserv,

I'm worriedI've been misunderstanding the t.cols argument in prediction of various models, so I'm hoping to get some advice/clarification. 

My current use is in a set of stPGOcc and svcTPGOcc models. The data set I'm using covers 19 years (the structure of data.list$y is [1:1134, 1:19, 1:26]). Many sites are surveyed only a couple years out of that time frame (with many missing years in between). I tried both ar1 = TRUE and ar1 = FALSE plus a random effect for year (ar1 = FALSE + RE for year performed better so I used that form).

For prediction, my goal is to predict only as close to current time as possible. So when generating X.0, I use only the most recent year of data available for the covariates in the model. So, the dimensions of X.0 are:
    dim1 = number of sites for prediction (which is many more than our sampled sites),
    dim2 = 1 (a single year of covariate values, i.e., latest year available for each covariate), 
    dim3 = 7 (Intercept plus number of covariates in my model),
and I set t.cols = 1 in the predict function. 

Overall my predict set up is this (I'm separating the prediction into chunks because of the number of sites and computing limits):

  tmp.X.pred <- array(NA, dim = c(length(starts[i]:stops[i]), 1, 7))
  tmp.X.pred[,,1] <- 1
  tmp.X.pred[,,2] <- annual_temp.0[starts[i]:stops[i]]
  tmp.X.pred[,,3] <- hii.0[starts[i]:stops[i]]
  tmp.X.pred[,,4] <- ndwi.0[starts[i]:stops[i]]
  tmp.X.pred[,,5] <- pntv.0[starts[i]:stops[i]]
  tmp.X.pred[,,6] <- precip_seasonality.0[starts[i]:stops[i]]
  tmp.X.pred[,,7] <- temp_seasonality.0[starts[i]:stops[I]]
 
  pred <- predict(
    mod,
    X.0 = tmp.X.pred, 
    t.cols = 1,
    coords = pred_coords[starts[i]:stops[i],],
    type = "occupancy", 
    ignore.RE = TRUE)

This ran fine for the stPGOcc models, but I am now getting this error when running it for the svcTPGocc models:

"error: when predicting at sampled sites using svcTPGOcc, you must predict across all primary time periods"

I'm worried that I might not understand the requirements of t.cols and/or that I'm screwing something up here trying to predict to only the latest year of covariate data available. 

Would appreciate any thoughts or advice.

Thanks in advance, take care!
Sara

Jeffrey Doser

unread,
Jul 27, 2026, 5:54:56 AM (4 days ago) Jul 27
to Sara Williams, spOccupancy and spAbundance users
Hi Sara, 

Thanks for the question. The t.cols functionality is not very well documented, so I certainly understand the need for clarification. 

The t.cols argument is only relevant when predicting with AR(1) random effects (i.e., ar1 = TRUE). It is used to make sure the prediction correctly pulls the right years based on what you want to predict. In that case, the value of t.cols should correspond to the index of the years that you want to predict. So, in your case, if you were using ar1 = TRUE and only wanted to predict for the last year, you would set t.cols = 19, since 19 corresponds to the last year out of all the years used when you fit the model. 

In your case, with ar1 = FALSE and instead a year random effect, the predict function will automatically be able to determine the years you want to predict for based on the values of the year random effect that you add into the X.0 prediction array. Assuming that you specified those with the value that corresponds to the value of the last year when you fit the model, then you should be good to go. 

Now, the problem with the error at predicting at all sites is some clunky behavior that I'll need to clean up. Basically, if you try to use the predict function to predict at a site where the model was fit, svcTPGOcc requires you to predict for all years in the data set. This is not ideal behavior, but there are two workarounds. 
  1. Remove the sites from the prediction set where you already fit the model. Those values can be extracted from the model output object itself in the "psi.samples" component of the model output list. It will contain predictions for each year and each site where at least one data point was available, giving you an estimated value for all years, even those that weren't sampled. You can then just extract the final year of those predictions. Then, for the sites without any fitted data, you would be able to predict just for the single year after removing the sites that had data when you fit the model. 
  2. You could just repeat the covariate values across all years in the X.0 array such that your second dimension of that array was 19. Then you would predict across all 19 years, with the only valid ones really being the 19th one, which you would then just extract after the prediction is done. 
The first approach is probably the better one to try. 

Hope that helps! Let me know if I can clarify anything, and sorry for the cryptic errors!

Jeff

--
You received this message because you are subscribed to the Google Groups "spOccupancy and spAbundance users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spocc-spabund-u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/spocc-spabund-users/84a5aa38-9336-422f-b4f8-d45b45e236cfn%40googlegroups.com.


--
Jeffrey W. Doser, Ph.D.
Assistant Professor
Department of Forestry and Environmental Resources
North Carolina State University

Sara Williams

unread,
Jul 27, 2026, 10:55:21 AM (4 days ago) Jul 27
to Jeffrey Doser, spOccupancy and spAbundance users
Hey Jeff,

This info helps a ton. Thank you very much for the additional explanation and quick reply!

Take care,
Sara
Reply all
Reply to author
Forward
0 new messages