Using temperature as a time varying session-specific covariate

283 views
Skip to first unread message

Chris Woolley

unread,
Jan 11, 2020, 8:07:29 PM1/11/20
to secr

Hi all, 

 

This is my first attempt at using secr so apologies if my explanation is unclear.

I am using secr to try to estimate density of skink populations and my issue is regarding how to add daily temperature to my models as a session-specific time varying covariate.


I have 16 trapping grids (of 25 traps, at 2m spacing) spread between two cities that have been monitored daily for 7-10 day periods three times over the course of my study (Nov 17, Jan 18 and Nov 18). I'm treating populations as closed within each period and am only using captures of one species. 

 

To analyse, my approach has been to model each trapping period separately including all sites together as 'sessions' using: 


Nov17 <- read.capthist("~/secr/Nov17.txt", "~/secr/trapfile.txt", 
                         detector = "multi")

Jan18 <- read.capthist("~/secr/Jan18.txt", "~/secr/trapfile.txt", 
                         detector = "multi")


Nov18 <- read.capthist("~/secr/Nov18.txt", "~/secr/trapfile.txt", 
                         detector = "multi")


fit_Nov17<-secr.fit(Nov17, start = list(D=1000, g0 = 0.01, sigma = 1), model = D ~session, buffer = 10, detectfn = 'HN', trace = FALSE) ### not sure if all these arguments are required

fit_Jan18<-secr.fit(Jan18, start = list(D=1000, g0 = 0.01, sigma = 1), model = D ~session, buffer = 10, detectfn = 'HN', trace = FALSE) 

fit_Nov18<-secr.fit(Nov18, start = list(D=1000, g0 = 0.01, sigma = 1), model = D ~session, buffer = 10, detectfn = 'HN', trace = FALSE)

 

fit_Nov17<-summary(fit_Nov17)

fit_Jan18<-summary(fit_Jan18)

fit_Nov18<-summary(fit_Nov18)


I'm keen to use a model selection approach to see how daily temperature and behavioural responses to capture affect model fit. However, my current difficulty is how to include temperature as a covariate that varies by occasion. I understand this can be done using timecov() ....

 

## something like...

fit_Nov17<-secr.fit(Nov17, start = list(D=1000, g0 = 0.01, sigma = 1), model = list(D~session, g0~tcov), buffer = 10, detectfn = 'HN', trace = FALSE, timecov = c(21.2, 19.3, 20.0, 21.1, 20.9, 19.4, 20.7))

 

.... however, as the trapping grids ('sessions') are spread across two cities (and therefore were not in use simultaneously) I'd like the temperatures to be specific to the session as well as varying with time. Is this possible or would it be best to model the trapping periods of each city separately (this would greatly reduce my already small sample size)?


Any advice or assistance would be greatly appreciated. Please let me know if more detail is needed to understand the problem.


Many thanks

Chris

Murray Efford

unread,
Jan 13, 2020, 7:01:25 PM1/13/20
to secr
Hi Chris

For multisession data in which time covariates differ among sessions it should work to provide timecov as an R list in which each component is the vector of time covariates (temperatures) for one session. This should be documented somewhere! Testing it I discovered a bug that causes an error if the number of occasions per session varies, but there is an easy workaround (pad the covariate vector for short sessions with NA).

Hence, generating some fake covariates for the ovenbird dataset,
#  number of occasions per session
> sapply(ovenCH, ncol)
2005 2006 2007 2008 2009 
   9   10   10   10   10 
# list of fake time covariates; session names not needed > dummycov <- list('2005' = c(13 + runif(9)*3, NA), # padded to length 10 + '2006' = 13+runif(10), + '2007' = 12+runif(10), + '2008' = 12+runif(10)*2, + '2009' = 11+runif(10)*3)
# review
sapply(dummycov, round,1) 2005 2006 2007 2008 2009 [1,] 14.2 13.3 13.0 13.2 12.5 [2,] 13.9 13.4 12.2 13.4 13.0 [3,] 14.4 13.0 12.9 12.7 13.8 [4,] 14.1 13.1 12.7 12.7 12.2 [5,] 15.9 13.8 12.9 12.9 11.7 [6,] 13.2 13.3 12.6 13.1 13.1 [7,] 15.6 13.9 12.5 12.9 12.3 [8,] 15.4 13.2 12.6 14.0 14.0 [9,] 16.0 13.2 12.2 12.9 11.5 [10,] NA 13.5 12.1 12.4 13.3

# fit a model
> secr.fit(ovenCH, timecov = dummycov, model = g0~tcov) Checking data Preparing detection design matrices Preparing density design matrix Finding initial parameter values... Initial values D = 1.37032, g0 = 0.02977, sigma = 62.87329 Maximizing likelihood... Eval Loglik D g0 g0.tcov sigma 1 -936.694 0.3150 -3.4842 0.0000 4.1411
etc.

Murray

Murray Efford

unread,
Jan 13, 2020, 7:13:48 PM1/13/20
to secr
Further hint: you will find it much quicker to bin temperatures so there are not so many unique values. Even rounding to 0.1 sped up my example, and rounding to nearest 0.5 or 1.0 was much faster.

Chris Woolley

unread,
Jan 16, 2020, 8:24:42 PM1/16/20
to secr
Thanks very much for your very fast response Murray. That's working now.
Many thanks
Chris

Manon Dalibard

unread,
Mar 1, 2021, 6:25:35 AM3/1/21
to secr
Dear SECR users,

I would like to pick up on the issue of Chris concerning the addition of time varying covariates differing among sessions in multisession models. As Chris, I would like to explore the effect of the temperature, as time varying covariate, on the estimation of demographic parameters of three stream-dwelling newt populations (i.e. three sessions, spatially independant). I am using secrlinear package (secr 4.3.3).
I have 3 or 4 occasions per session, all realized during the activity period of the species. Each session has its own detector layout.
I used the method proposed by Murray to construct a list of time varying covariates but I have some troubles when fitting the model.

Here is my process:

# list of time covariates
multi_tcov_2019 <- list('cassrats' = c(NA,cassrats_tcov[1:3,3]),
                        'Fougax' = c(fougax_tcov[12:15,3]),
                        'Salau' = c(NA,NA,salau_tcov[5:6,3]))

timevaryingcov(multi_tcov_2019$cassrats)<- list(blockt = 1:4)
timevaryingcov(multi_tcov_2019$Fougax)<- list(blockt = 1:4)
timevaryingcov(multi_tcov_2019$Salau)<- list(blockt = 1:4)

# output (there is some occasions with NA in two sessions)
> multi_tcov_2019
$`cassrats` [1] NA 10.6505 12.1100 14.7090
attr(,"timevaryingcov")
attr(,"timevaryingcov")$`blockt`
[1] 1 2 3 4

$Fougax [1] 14.9475 16.8080 15.1865 12.8830
attr(,"timevaryingcov")
attr(,"timevaryingcov")$`blockt`
[1] 1 2 3 4

$Salau [1] NA 18.616 15.091 NA
attr(,"timevaryingcov")
attr(,"timevaryingcov")$`blockt`
[1] 1 2 3 4

# fit the model
fitmulti_2019_11 <- secr.fit(casper2019_multi_tous, mask = list(cassratsstreammask, fougaxstreammask, salaustreammask), trace = FALSE,
                             model = list(g0~tcov+session), hcov = "Sex",
                             timecov = multi_tcov_2019,
                             details = list(userdist = networkdistance))

Warning messages:
1: In secr.design.MS(capthist, model, timecov, sessioncov, groups, :   # I supposed this is due to the NAs in short sessions
length of 'timecov' exceeds number of occasions
2: In secr.design.MS(capthist, model, timecov, sessioncov, groups, :
length of 'timecov' exceeds number of occasions
3: In secr.fit(casper2019_multi_tous, mask = list(cassratsstreammask, : at least one variance calculation failed

# output of the predictions
model_predictions.JPG


When I check the predictions of my model, there is no predictions for the different levels of my time variable but only for 0° (while I don't have any 0° in the time varying datasets).


I would really appreciate any advice or assistance!
Let me know if more detail is needed.

Thanks in advance
Manon

Murray Efford

unread,
Mar 1, 2021, 3:14:58 PM3/1/21
to secr
See the 'newdata' argument of predict() for this sort of thing. Your model is getting too intricate for me to follow without doing the analysis myself, and there may be other problems. It doesn't help to append a new question to an old thread.

Manon Dalibard

unread,
Mar 2, 2021, 3:19:55 AM3/2/21
to secr
Hi Murray,

My apologies for wrongly placing my request. I will take a deeper look at the newdata argument and create a new conversation if the problem persists.

Thank you
Manon
Reply all
Reply to author
Forward
0 new messages