colext: how to use the predict function

1,002 views
Skip to first unread message

Viorel Popescu

unread,
Apr 20, 2011, 10:18:10 PM4/20/11
to unmarked
Hi everyone,

I am new to 'unmarked' and I am trying to run multi-season models on
simulated data with colext. Per a previous discussion thread by Ben
Zuckerberg, I was wondering if 'predict' is currently implemented for
colext objects.
The dataset is simple: there are 10 years and the sites are split
between 2 different types of habitats. After fitting some simple
models, I want to get estimates for psi, col, ext and det for each of
the 2 habitat types for each year using 'predict'. I followed the on-
line examples (including the one for colext), but I couldn't get any
results; it probably has to do with parametrizing the new data.frame
needed for 'predict'. Do you have any suggestions or directions to
other on-line help?

Thank you...

Viorel

Richard Chandler

unread,
Apr 21, 2011, 9:45:35 AM4/21/11
to unma...@googlegroups.com
Hi Viorel,

If you have version 0.9-0, you can run the first part of the colext example and then do this:

fm <- colext(~x2, ~x2, ~x2, ~x2, umf)
nd <- data.frame(x2=c("A", "B"))
predict(fm, type="psi", newdata=nd)
predict(fm, type="col", newdata=nd)
predict(fm, type="ext", newdata=nd)
predict(fm, type="det", newdata=nd)

Does that help?

Richard

Viorel Popescu

unread,
Apr 21, 2011, 12:09:11 PM4/21/11
to unma...@googlegroups.com
Thank you Richard... this was very helpful

I ran the model as you suggested and I am indeed getting the estimates for each treatment; but are those values estimates across all years? This might be a silly question, but is there a way to obtain those estimates for each year and habitat type separately? For my simulations I want to look at trends... Thank you

Cheers,
Viorel

Richard Chandler

unread,
Apr 21, 2011, 1:21:16 PM4/21/11
to unma...@googlegroups.com
Not a silly question at all. Using the example again, try this

fm <- colext(~x2, ~x2, ~x2, ~x2+year, umf)
nd <- expand.grid(year=c("year1", "year2"), x2=c("A", "B"))
predict(fm, type="det", newdata=nd, appendData=TRUE)

Each row of "newdata" should have the combination of covariates for which you want a prediction.

Also, I want to let people know that Marc Kery is writing a tutorial to help people get started with the colext function. It would be great if other people wanted to improve the documentation too. Please let me know if you are interested.

Richard

Viorel Popescu

unread,
Apr 21, 2011, 4:46:56 PM4/21/11
to unma...@googlegroups.com
Hi Richard, 

It did work for both the year+treat and year*treat (thanks a lot). I also have tried the same combinations on colonization and extinction. The models converge with no problems, but I obtain the following error when I use the 'predict' function for ext or col (using the same new data.frame):  Error: ncol(coefficients) == length(obj@estimates) is not TRUE
Years are inserted in the model as yearlySiteCovs.

Also, is it possible to obtain yearly estimates for occupancy from 'predict'? Or is it possible only from 'projected' or 'smoothed'?

Thank you
 
A tutorial and improving the documentation for colext would be of great help for anyone starting with it...

Cheers,
Viorel  

Richard Chandler

unread,
Apr 22, 2011, 7:59:07 AM4/22/11
to unma...@googlegroups.com
Hi Viorel,

Did you remember that there are nYears-1 possible estimates of "col" and "ext"? Not nYears. So you cannot include the last year in "newdata". Continuing with the end of the colext example:

nd <- data.frame(year=paste('year', 1:6))
predict(fm.yearly, type="ext", newdata=nd)

This would fail if you tried 1:7 instead of 1:6.

Predict will not give you yearly estimates of psi. But what is wrong with the smoothed and projected values? The example shows how to get confidence intervals using a nonparametric bootstrap. Other options exist as have been discussed on an earlier thread.

Richard

Viorel Popescu

unread,
Apr 26, 2011, 12:26:55 PM4/26/11
to unma...@googlegroups.com
Thank you Richard, this was very helpful to understand how colext works. There is nothing wrong with the projected values; I was just wondering if there a was a faster way to get the confidence intervals since I was planning in running multiple simulations; nonetheless, np bootstrapping worked just fine.   
I am getting all I need from the models now...

Cheers,
Viorel

Vincent CLEMENT

unread,
Oct 9, 2024, 8:06:14 AM10/9/24
to unmarked
Hi,

I stumbled upon this thread and thought it might answer a question I was pondering lately, but it I think it left it open.
I am trying to get yearly estimates of psi for each treatment of a site covariate. Looks like part of what Viorel was asking. I can get yearly estimates of psi with smoothed or projected values, or estimates of psi for each treatment across years with predict. But is there a way to look at occupancy for each year AND each factor of a site covariate simultaneously ?

Cheers
Vincent
Reply all
Reply to author
Forward
0 new messages