Predict - Some help with coding

questions concerning anlysis/theory using program DENSITY and R package secr. Focus on spatially-explicit analysis.

Predict - Some help with coding

Postby Isoodon » Tue Aug 26, 2014 2:23 am

Hi Murray,

I am trying to plot the detection probability for naive and experienced Bandicoots across sexes. The preferred SECR model is fit.b2.h2 that you would be familiar with from previous years.

fit.b2.h2 <- secr.fit(myall2014, verify=F, model = list(g0~b+h2, sigma~b+h2),hcov = 'sex', buffer=400, trace = FALSE)

I can then plot the detection probability for naive males and females:

plot (fit.b2.h2, xval = 0:250, ylim = c(0, 0.3))

but when I try and add experienced animals using:

plot (fit.b2.h2, newdata = data.frame(b=1), add = TRUE, col = "red")

I get the following error:

Error in secr.lpredictor(newdata = newdata, model = models[[x]], indx = parindices[[x]], :
one or more model covariates not found in 'new data'

If you could assist with interpreting this error I would be most appreciative.

All the best,

Roy
Isoodon
 
Posts: 4
Joined: Tue Jun 25, 2013 8:50 pm

Re: Predict - Some help with coding

Postby murray.efford » Tue Aug 26, 2014 3:33 am

Hi there
This is just a matter of how secr constructs the 'real' parameter estimates. It uses the function predict.secr which has the argument newdata, a dataframe with a column for each covariate or other effect. As you understood, the default value of newdata is a simplified version - for example, it omits the `experienced' level of the learned response b. You can reveal the default value by setting the 'savenew' argument. Here is an example using a model equivalent to yours, fitted to some ovenbird mistnetting data from 2005:
Code: Select all
 fit <- secr.fit(ovenCH[[1]], model=list(g0 ~ b + h2), hcov='Sex')
[edited]
predict(fit, savenew=T)
$`session = 2005, h2 = F, b = 0`
       link   estimate SE.estimate          lcl         ucl
D       log  1.1087312  0.31308697  0.644253160   1.9080775
g0    logit  0.0263223  0.01945016  0.006071384   0.1068576
sigma   log 84.9792870 16.99077473 57.648590481 125.2672294
pmix  logit  0.3593732  0.11672335  0.171962032   0.6024332

$`session = 2005, h2 = M, b = 0`
       link    estimate SE.estimate          lcl          ucl
D       log  1.10873124  0.31308697  0.644253160   1.90807750
g0    logit  0.02972118  0.01670556  0.009745877   0.08703957
sigma   log 84.97928695 16.99077473 57.648590481 125.26722945
pmix  logit  0.64062683  0.11672335  0.397566826   0.82803797

attr(,"newdata")
  session h2 b
1    2005  F 0
2    2005  M 0

You see that the newdata (scroll to bottom) includes a column for the mixture components (here F and M). To get the result you want, you must also provide this column:
Code: Select all
 plot(fit)
plot(fit, newdata = data.frame(b = c(1,1), h2 = c('F', 'M')), col = 'red', add = TRUE)

If you set newdata it has to be complete (except for 'session' that isn't used in the model). I hope that settles it.
Murray
murray.efford
 
Posts: 712
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Predict - Some help with coding

Postby Isoodon » Wed Aug 27, 2014 4:06 am

Thanks Murray - did the trick.

R
Isoodon
 
Posts: 4
Joined: Tue Jun 25, 2013 8:50 pm


Return to analysis help

Who is online

Users browsing this forum: Google Adsense [Bot] and 2 guests