by mdrever » Thu Oct 25, 2018 5:51 pm
hello SECR list,
I am struggling with adding habitat covariates to a multiple session model. We have capture/resight data for skinks from two big plots (625 detectors each at 'Shilo' and 'SWPP') in Manitoba, Canada. We have a very low resight rate (14 resights from >500 individuals marked at the two plots combined), and so I have used a suggestion from elsewhere in the forum to look at the two plots as separate sessions in order to maximize the available data on resights to estimate g0 and sigma. I may be pushing the data too far, but the majority of the capture happen in two of the three habitat types, and it would good to formally test for that difference. However, when I try to add the habitat covariates, I seem to convert my capt.hist into a traps object. Any help would be greatly appreciated. Annotated code and errors follow below. thank you very much for any guidance,
Mark.
## make the capture history as two sessions
skinks.CH <- read.capthist('skinks.txt', c('swpp.grid.txt','shilo.grid.txt'), detector = "multi",
covnames = 'Age', noccasions = 14 )
summary(skinks.CH) ## capture histories as a list ## plotting them looks as it should
#The plot effect can be tested by comparing the two models: ## this section runs well
#EX chosen by AIC from other available functions
fit0 <- secr.fit(skinks.CH, model = D ~ 1, buffer = 25, detectfn ='EX')
fit1 <- secr.fit(skinks.CH, model = D ~ session, buffer = 25, start = fit0, detectfn ='EX')
## compare the models ## supports different densities at the two sites (not shown)
fits <- secrlist(fit0 =fit0,fit1 =fit1 )
AIC (fits)
############## make the habitat masks ############################
covariates(traps(skinks.CH)[[1]]) <- all.grids[all.grids$Grid == 'SHILO',c('Habitat.Type')]
covariates(traps(skinks.CH)[[2]]) <- all.grids[all.grids$Grid == 'SWPP',c('Habitat.Type')]
names(attr(skinks.CH[[1]], "covariates")) <- 'Habitat.Type'
names(attr(skinks.CH[[2]], "covariates")) <- 'Habitat.Type'
skinks.mask <- make.mask(traps(skinks.CH), type = 'traprect', buffer = 17.5 )
skinks.mask <- addCovariates(skinks.mask, traps(skinks.CH), 'Habitat.Type', replace = TRUE)
names(attr(skinks.mask[[1]], "covariates")) <- 'Habitat.Type'
names(attr(skinks.mask[[2]], "covariates")) <- 'Habitat.Type'
## plotting the masks looks correct (not shown)
# adding the habitat mask to the model, and resulting error
fit2 <- secr.fit(skinks.CH, model = D ~ session + Habitat.Type , buffer = 25,
mask = skinks.mask , detectfn ='EX')
Error in secr.fit(skinks.CH, model = D ~ session + Habitat.Type, buffer = 25, :
requires 'capthist' object
> class(skinks.CH)
[1] "traps" "list"
> str(skinks.CH)
List of 2
$ : capthist [1:101, 1:14, 1:625] 0 0 0 0 0 0 0 0 0 0 ...
..- attr(*, "dimnames")=List of 3
.. ..$ : chr [1:101] "UNIQ011" "UNIQ012" "UNIQ013" "UNIQ014" ...
.. ..$ : chr [1:14] "1" "2" "3" "4" ...
.. ..$ : chr [1:625] "1" "2" "3" "4" ...
..- attr(*, "covariates")='data.frame': 101 obs. of 1 variable:
.. ..$ Habitat.Type: Factor w/ 3 levels "A","H","J": 3 1 1 3 1 3 1 1 1 1 ...
..- attr(*, "traps")=Classes ‘traps’ and 'data.frame': 625 obs. of 2 variables:
.. ..$ x: int [1:625] 250 325 275 25 525 250 350 450 400 225 ...
.. ..$ y: int [1:625] 325 400 325 475 0 500 325 500 225 350 ...
.. ..- attr(*, "detector")= chr "multi"
.. ..- attr(*, "spacex")= num 25
.. ..- attr(*, "spacey")= num 25
.. ..- attr(*, "spacing")= num 25
.. ..- attr(*, "covariates")='data.frame': 625 obs. of 1 variable:
.. .. ..$ value: Factor w/ 3 levels "Grassland","Open Woods",..: 1 1 1 1 1 1 1 1 1 1 ...
..- attr(*, "session")= chr "SHILO"
$ : capthist [1:340, 1:14, 1:625] 0 0 0 0 0 0 0 0 0 0 ...
..- attr(*, "dimnames")=List of 3
.. ..$ : chr [1:340] "UNIQ001" "UNIQ002" "UNIQ003" "UNIQ004" ...
.. ..$ : chr [1:14] "1" "2" "3" "4" ...
.. ..$ : chr [1:625] "1" "2" "3" "4" ...
..- attr(*, "covariates")='data.frame': 340 obs. of 1 variable:
.. ..$ Habitat.Type: Factor w/ 3 levels "A","H","J": 1 1 3 3 1 3 3 1 3 1 ...
..- attr(*, "traps")=Classes ‘traps’ and 'data.frame': 625 obs. of 2 variables:
.. ..$ x: int [1:625] 25 525 150 200 150 375 25 425 475 25 ...
.. ..$ y: int [1:625] 600 200 200 500 225 225 275 325 200 225 ...
.. ..- attr(*, "detector")= chr "multi"
.. ..- attr(*, "spacex")= num 25
.. ..- attr(*, "spacey")= num 25
.. ..- attr(*, "spacing")= num 25
.. ..- attr(*, "covariates")='data.frame': 625 obs. of 1 variable:
.. .. ..$ value: Factor w/ 3 levels "Grassland","Open Woods",..: 1 1 1 1 1 1 1 1 1 1 ...
..- attr(*, "session")= chr "SWPP"
- attr(*, "class")= chr [1:2] "traps" "list"