Page 1 of 1

read.caphist questions

PostPosted: Sat May 09, 2015 6:40 pm
by Bryan Hamilton
Progress is really slow. I'm able read some of my data when its heavily subsetted but I haven't been able to move on to co-variates or model selection.

1. Can I read R dataframes directly with 'read.caphist' ? I'd like to get away from creating text files every time a make small change to my data.

2. How do I specify the 'covnames' in 'read.caphist' ? Right now they are column names in my text files but I get error messages when I enter them.

3. Are there some single detector examples out there? I've tried the deermouse and housemouse examples but I can't get into the guts of the data. I'd like to be able to see the data structure and how the models were constructed.

I'm convinced that secr is the right way to analyze my data but I'm really feeling the learning curve right now.

Re: read.caphist questions

PostPosted: Sat May 09, 2015 8:17 pm
by murray.efford
1. Use make.capthist if your capture data are already an R dataframe (after using read.traps separately to construct the detector layout)

2. covnames is a "character vector of names for individual covariate fields" with length equal to the number of individual covariates (specifying covnames is optional - but recommended so the names are meaningful).

3. Too vague to answer. Examples of data entry for single-catch traps? No need - it's identical to the stoat example in http://www.otago.ac.nz/density/pdfs/secr-datainput.pdf that I assume you have already followed.

Re: read.caphist questions

PostPosted: Sat May 09, 2015 8:44 pm
by Bryan Hamilton
Thank you.

1. I'll try this right now and report back.

2. I think I see. If I have two covariates in my capture history (gender and mass), I'd have a vector similar to c(gender, mass)? Maybe I should just post some reproducible code here.

3. The deer mouse and house mouse examples are all pre-packaged , so I can't (or more likely don't know how) see the model structure or the original data. The stoat example doesn't have covariates so there aren't any examples of showing models with covariates.

Right now I'm trying to figure out 'make.mask' and it just isn't working.

Re: read.caphist questions

PostPosted: Sat May 09, 2015 9:02 pm
by Bryan Hamilton
With 'read.traps' the trap identifier is lost? So then you have to keep the x, y coordinates in each row of the capture history dataframe?

Re: read.caphist questions

PostPosted: Sat May 09, 2015 9:28 pm
by Bryan Hamilton
Here is my capture history data:

Code: Select all
   head(query)
     Year AnimalID occasion trapID Gender MeanWeight AOU_Code
4746 2014      764        1  001A6      M      15.25     PEMA
4747 2014      796        1  001C6      M      13.50     REME
4748 2014      754        1  001C7      M      17.50     PEMA
4749 2014      752        1  001E5      F      12.75     PEMA
4750 2014      037        1  003A6      M      54.00     TADO
4751 2014      027        1  003B1      M      22.50     PETR


trap data:

Code: Select all
  trapID      x       y
1   008G1 739349 4322409
22  005G4 739811 4322124
24  010B6 740431 4322231
56  009G4 739919 4322361
57  009E4 739919 4322391
64  001A4 741398 4321616


Code: Select all
traps <- read.traps(data = trap,detector = "single",fmt="trapID")
> head(traps)
        x       y
1  739349 4322409
22 739811 4322124
24 740431 4322231
56 739919 4322361
57 739919 4322391
64 741398 4321616


When I use the 'read.traps command, the trap ID is gone.

So my two questions are:

1. Why is the trapID gone?
2. How do I specify the covariates names? These are Gender,MeanWeight, and AOU_Code.

Re: read.caphist questions

PostPosted: Sat May 09, 2015 10:58 pm
by murray.efford
Hi again
1. read.traps takes the row names of an input dataframe and uses them as the trap identifiers (the row names of the output). So try
Code: Select all
rownames(trap) <- trap$TrapID
traps <- read.traps(data = trap, detector = "single")
(Note fmt is not an argument of read.traps - it's used by read.capthist and make.capthist).
2. I think it's as simple as putting your covariate names in quotes (single or double). Without quotes they are not character values but the names of R objects that don't exist.
Code: Select all
... covnames = c('Gender','MeanWeight', 'AOU_Code')...

I see your point about the lack if a full example with covariates... You can reverse engineeer housemouse with
Code: Select all
 write.capthist(housemouse, tonumeric = FALSE)
Look in your working direcory for files housemousecapt.txt and housemousetrap.txt. Then this code should work
Code: Select all
coulombe <- read.capthist('housemousecapt.txt', 'housemousetrap.txt',
    detector = 'single', covnames = c('sex','age'))
summary(coulombe)
head(covariates(coulombe))

Murray

Re: read.caphist questions

PostPosted: Sat May 09, 2015 11:43 pm
by Bryan Hamilton
Thank you so much. I feel like I'm getting closer to getting some real analysis done.

Re: read.caphist questions

PostPosted: Sun May 10, 2015 6:45 pm
by Bryan Hamilton
Hello

I'm edging ever closer to some hypothesis testing.

I believe I have figured out how to specify co-variates. For a factor like sex or species, this is how I've written the model. Is there a way to specify the covariate directly by name in the model?

Code: Select all
sex <- secr.fit(CH, model = list(D~1, g0~g, sigma~1),groups='gender',
+ buffer = 150, trace = FALSE) #sex as a covariate for g0


How would I incorporate a continuous co-variate such as mass? I haven't been able to figure that out.

The density estimates seem really low (~1 per hectare). For a subset of my data, I had captured 34 animals on 11 grids, each grid samples about one hectare (90x90m). Using Minimum Number Known Alive would give a density of about 3 animals per hectare. I don't understand how density would be less than that.

Also when I include all my data, the model output is all NA. My data set is big 11 years, with each year as a session, and about 5,000 captures. Is this an issue with computing power? The data loaded with no errors in the 'read.capthist'.

Code: Select all
$`session = 2004`
       link estimate SE.estimate lcl ucl
D       log       NA          NA  NA  NA
g0    logit       NA          NA  NA  NA
sigma   log       NA          NA  NA  NA

Re: read.caphist questions

PostPosted: Sun May 10, 2015 7:50 pm
by murray.efford
You have strictly defined 'genders' (sexes) as groups, not used sex as a covariate.

How would I incorporate a continuous co-variate such as mass?

1. Don't do it until you have mastered the rest.
2. Individual covariates require a conditional-likelihood approach (CL=TRUE) and tend to be slow to fit (less slow if you discretize into a few classes).
3. Individual covariates must be permanent; you can use e.g. mass at first capture
Code: Select all
mass <- secr.fit(CH, CL = TRUE, model = list(g0~mass, sigma~1),
 buffer = 150, trace = FALSE) # mass as a covariate for g0


The density estimates seem really low

Naive estimates, with which you are comparing them, are usually biased high, sometimes by quite a lot, because the animals caught on the grid come from further afield.

Also when I include all my data, the model output is all NA.

My guess is that this is a problem with starting values; by default these are based on the first session, which may be inadequate or extreme. You can specify start = list(D=1, g0=0.2, sigma=25) or whatever as an argument to secr.fit. (The next version of secr allows you to nominate the session on which starting values will be based, but let's not go there).

However, you should master the basics first. For example, fit a separate model to each year with
Code: Select all
lapply(CH, secr.fit, buffer = 150, trace = FALSE)


This is fast and should give you a clear idea of what to expect.

Re: read.caphist questions

PostPosted: Mon May 11, 2015 2:44 pm
by Bryan Hamilton
You have strictly defined 'genders' (sexes) as groups, not used sex as a covariate.


What are the differences between covariates and groups? In RMark groups are categorical variables and covariates are continuous. Is secr similar?

When I run gender as a covariate, there are no density estimates. Why is this?

Code: Select all
> secrG <- secr.fit(CH, model = list(D~gender,g0~gender,sigma~1), buffer = 150, trace = FALSE,CL = TRUE) #gender as a co-variate

Code: Select all
> predict(secrG)
       link    estimate SE.estimate         lcl         ucl
g0    logit  0.06276427  0.01207055  0.04287181  0.09100915
sigma   log 34.90974083  2.44352804 30.43960769 40.03632428


1. Don't do it until you have mastered the rest.


By this do you mean, test some models with some variation in detection parameters? I've tested quite a few and the differences in density between models are pretty trivial. I would interpret this as now its time to add some additional covariates and start hypothesis testing.

Code: Select all
Naive estimates, with which you are comparing them, are usually biased high, sometimes by quite a lot, because the animals caught on the grid come from further afield.


This is really cool. Its making me glad I'm learning this package. Its neat to see the secr of low densities of pinyon mice and high densities of voles, even though we captured more pinon mice. Its counter intuitive at first but its starting make sense.

However, you should master the basics first.


I'd appreciate any more advice on mastering the basics.

Thank you.