Problem: polygons with varying effort

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

Problem: polygons with varying effort

Postby sbraun » Fri Apr 26, 2024 3:14 am

Hi everyone
I’m new to secr and try to analyse my data on hares.
I have data of individual hares (two hare species) extracted of hare faeces. We survey the area now for five years collecting data twice in the middle of summer and twice at the end of the summer. Hence, we have 10 sessions (middle and end for 5 years, coded as 1-10) and two occasions per session (coded as 1 and 2).
We are searching 7 polygons. However, 2 polygons were included new in the fourth year. In the fourth year, the new polygons were searched only twice (only once per session). In the fifth year, the were searched four times (as polygons 1-5).
The problem occurs by coding for the usage. I coded for polygons 1-5 usage: 11111111111111111111 (20times= 10 sessions * 2 occasions). For polygons 6 and 7, I coded usage: 00000000000001011111 (first three years: no data collection, 4th year: only 2 out of 4, and 5th year: full data collection). When doing read.capthist(), the message appears:
Fehler in read.traps(file = "perimeter.txt", detector = "polygon", covnames = NULL, :
usage input not available for polygon detectors in 4.5
I have installed secr 4.6.6
As I will continue collecting data on all 7 transects for the next 5 years, I really want to find a solution to include the new transects 6 and 7.
Thank you very much for your help!
Kind regards, Stéphanie
sbraun
 
Posts: 5
Joined: Tue Apr 23, 2024 5:08 am

Re: Problem: polygons with varying effort

Postby murray.efford » Fri Apr 26, 2024 5:04 am

Hello Stephanie
That error message still applies, but it should not refer to a version. I think I gave up trying to handle the complexities of usage input for polygons because each polygon (= detector) has several input rows (vertices). You need to add the usage 'manually' after creating the traps object. That isn't hard. Here is a mocked up example

Suppose you have a text file 'usage.txt' with the lines

11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
00000000000001011111
00000000000001011111

And a 7-polygon traps object 'poly'
I made a dummy example with this code, but you will have the real thing:
poly1 <- make.poly()
poly <- do.call(rbind, rep(list(poly1),7))

Then:
mat <- read.fwf('usage.txt', rep(1,20))
usage(poly) <- mat

However this gives you a single-session structure with 20 occasions. That can be used in 'openCR' to fit an open population model (assuming captures and intervals have been coded appropriately), but probably you want to start with closed models in 'secr'.

I think you can split the above object by session like this -
polys <- split(poly, f = rep(1:10, each = 2), byoccasion = TRUE)
usage(polys)

That leaves the problem of combining this with capture data in make.capthist...

Murray
murray.efford
 
Posts: 712
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Problem: polygons with varying effort

Postby sbraun » Tue May 07, 2024 5:42 am

Dear Murray
Thank you very much for your answer. I tried it out and it worked so far.
Do you know how to make a caphist object after the split?
Kind regards,
Stéphanie
sbraun
 
Posts: 5
Joined: Tue Apr 23, 2024 5:08 am

Re: Problem: polygons with varying effort

Postby murray.efford » Tue May 07, 2024 3:32 pm

This comes under the heading "When read.capthist is inadequate. . ." in the data-input vignette. I think you should check the help for make.capthist(). Briefly, make.capthist() accepts a dataframe of captures and an existing 'traps' object such as you have. The only problem, I think, is to match the order (names?) of sessions in the capture dataframe to each session-specific traps component.
Murray
murray.efford
 
Posts: 712
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Problem: polygons with varying effort

Postby sbraun » Thu May 23, 2024 4:44 am

Dear Murray
I could match them by using the same name and make a capthist object. It worked. Thank you very much.
I estimated a buffer:
RPSV(hares_eur, CC = TRUE)

I did a secr.fit with lapply:
fits <- lapply(hares_eur, secr.fit, buffer = 1713.7922, trace = FALSE)
class(fits) <- 'secrlist'
predict(fits)

The output looks reasonable. However, it give me the warning: using default starting values
Is that a problem? I didn't find anything about this warning in your secr pdfs (e.g., troubleshooting).
Kind regards,
Stéphanie
sbraun
 
Posts: 5
Joined: Tue Apr 23, 2024 5:08 am

Re: Problem: polygons with varying effort

Postby murray.efford » Thu May 23, 2024 11:46 pm

Hi Stephanie
That message is normal for polygon detectors. Try for example
FTHL.fit <- secr.fit(hornedlizardCH, buffer = 80, trace = FALSE)
as in the secr-polygondetectors pdf. You can specify start values if you wish (e.g., start = list(D=0.1, lambda0=0.1, sigma=20) or whatever seems reasonable). it should not affect the answer.
Murray
murray.efford
 
Posts: 712
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Problem: polygons with varying effort

Postby sbraun » Fri May 24, 2024 2:27 am

Dear Murray
Thank you very much. I wasn't sure and because I want to do it correctly I wanted to be sure.
I'm sorry but already the next problem arrises:
As I have 2 sessions per year, I want to model trends for 2 sessions, that means yearly trends. I tried the following (as suggested in the pdf secr multisession on page 6):

#create data frame as factors for the different years
year = as.data.frame(c('2019','2019','2020','2020','2021','2021','2022','2022','2023','2023'))
colnames(year)=c('y')
year$y<-as.factor(year$y)
#Assign the data frame to sessioncov
fits <- lapply(hares_eur, secr.fit,sessioncov="year", buffer = 1713.7922, trace = FALSE)
class(fits) <- 'secrlist'
predict(fits)

However, it does not work. It still gives me the densities for each session and not per year. Is it because I can't put sessioncov directly to secr.fit?

Your help here would be very much appreciated.

Later, I want to model trends accross all years. That means, it should calculate the trend using the model that I created above with the yearly trends. But how do I extract D.Session (as mentioned in the pdf secr multisession on page 5)? Or: how do I create this model.D?

Thank you very much in advance!
Kind regards,
Stéphanie
sbraun
 
Posts: 5
Joined: Tue Apr 23, 2024 5:08 am

Re: Problem: polygons with varying effort

Postby murray.efford » Wed Jun 12, 2024 4:08 am

My apologies for the slow service...

There are two problems - you don't actually fit a model using the year covariate, and 'y' is reserved for the y-coordinate of the habitat mask so you need to choose a different name. The sessioncov argument is merely a source for covariates mentioned in model formulae and has no effect in itself. See below for my coding suggestion. For a log-linear trend model (instead of distinct density each year) you would fit D~yr.
Murray

Code: Select all
# create data frame with numeric (yr) and factor (yf) year
years <- data.frame(yr = rep(2019:2023, each = 2))
years$yf <- factor(years$yr)
years

# fit model to multi-year data
setNumThreads(8)
fits <- secr.fit(hares_eur, model = D~yf, sessioncov = years,
                 buffer = 1800, trace = FALSE)

# predict from fitted model
predict(fits, all.levels = TRUE)
# or
predict(fits, newdata = years)

# another example
years <- data.frame(yf = factor(2005:2009))
msk <- make.mask(traps(ovenCHp[[1]]), buffer = 250, nx = 25)
fits <- secr.fit(ovenCHp, mask = msk, model = D~yf, sessioncov = years)
coef(fits)
predict(fits)
# or
predict(fits, newdata = years)
murray.efford
 
Posts: 712
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Problem: polygons with varying effort

Postby sbraun » Tue Jun 25, 2024 9:36 am

Dear Murray
Thank you very much for your help!
I estimated the densities for each year with your code “model = D~yf”. The output is showing each year twice ($`yr = 2019`, $`yr = 2019`, $`yr = 2020`,$`yr = 2020`,etc) but with the same values for each year. Hence, I think this worked.
When I model trends over the five years with your code “model = D~yr”, it gives me the following warning: “In getmaskpar(!CL, D, data$m, sessnum, details$unmash, ... : bad densities in 'secrloglikfn' (try different optimisation method, link, or model?)”
What did go wrong? Or did I do something incorrectly?
Could you tell me why you chose setNumThreads(8)?
Kind regards,
Stéphanie
sbraun
 
Posts: 5
Joined: Tue Apr 23, 2024 5:08 am

Re: Problem: polygons with varying effort

Postby murray.efford » Wed Jul 10, 2024 4:53 pm

Hello Stéphanie

I chose 'setNumThreads(8)' because 8 is a common number of available cores for parallel processing (on a quad-core Windows machine with virtual cores). You can use any number from 1 up to the maximum on your machine. I think you could have answered this by the simple expedient of reading the manual or ?setNumThreads.

You are learning SECR with a rather complex example, which is painful for everyone! Giving an answer to your other question would require forensic work on your data and code. I can take a look at it if you make it easy for me by sending all the bits (and no more).

Murray
murray.efford
 
Posts: 712
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Next

Return to analysis help

Who is online

Users browsing this forum: No registered users and 2 guests

cron