Time varying covariate error

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

Time varying covariate error

Postby jeff.stetz » Thu Dec 10, 2015 12:53 am

I'm receiving the following error when trying to run a model with a time varying covariate for g0.

Preparing detection design matrices
Error in `[.data.frame`(trcov, , indices) : undefined columns selected

I followed the example code in the vignette (and an earlier post that was, coincidentally, with nearly the same dataset):

> timevaryingcov(temptrap) <- list(blockt = 1:5)
> timevaryingcov(temptrap)
$blockt
[1] 1 2 3 4 5

Except in my case, I used the covariate names as listed in my 'read.traps' statement, per the vignette:

>timevaryingcov(bnp08.traps) <- list(evi_time = "evi145trap",...,"evi305trap"). Note, all covariates of interest are listed in the code, and the number of covariates does match the number of occasions (11).

>timevaryingcov(bnp08.traps)
$evi_time
[1] "evi145trap"

[[2]]
[1] "evi160trap"
...

[[11]]
[1] "evi305trap"

Just for good measure, I tried using the number of the columns (ie, list(evit_time=4:14)) which does produce an output similar to the example, but the same error is generated upon running the model. I even tried list("evi145trap":"evi305trap"), which gives an Na/NaN error.

Also, and Murray was already kind enough to give me some advice off-list for this, I'm interested in the most streamlined way to use quadratic terms, such as for g0~elevation. The notation I'm familiar with from lme4 doesn't work (ie, g0~elevation^2).

Thanks for any advice for this R idiot.
jeff.stetz
 
Posts: 3
Joined: Wed May 30, 2012 12:55 pm

Re: Time varying covariate error

Postby murray.efford » Thu Dec 10, 2015 1:14 am

The value should be a vector, so maybe your first example would work with
Code: Select all
timevaryingcov(bnp08.traps) <- list(evi_time = c("evi145trap",...,"evi305trap"))


Your second example should work if you have at least 14 covariates and just 11 occasions; if it doesn't I'll need to look again at the timevaryingcov code (it's been a year or two since I was aware of anyone using it). There is no way the third attempt would work because ":" expects numeric values.

As I indicated earlier, you can include a quadratic term in linear predictor by adding it as a covariate
Code: Select all
covariates(traps(CH))$elevation2 <- covariates(traps(CH))$elevation^2
secr.fit(CH, g0~elevation + elevation2)
murray.efford
 
Posts: 686
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand


Return to analysis help

Who is online

Users browsing this forum: No registered users and 14 guests