incorporating sex into analysis

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

incorporating sex into analysis

Postby cdevens226 » Wed Jul 01, 2015 8:25 am

Dear Murray,
I have messaged you previously about my density analysis for a large leopard camera trap survey across many regions in the Western Cape. My script has evolved to include a variety of different covariates like human footprint, anthropogenic biomes, veg coverage, land cover, bioclims etc in an effort to establish a leopard density derived from environmental as well as anthropogenic factors. Ultimately I want to illustrate how leopard density is affected by various factors that may or may not create edge effects across a highly modified landscape in the Cape.
At the moment I am trying to incorporate sex as a column in the capture file with “covnames = ‘Sex’” (capitalized because its capitalized in my capture excel file!?) in the read.capthist script and “hcov = 'Sex' in the secr.fit script (because I use M, F and NA).

My script:
Code: Select all
PP_ALLregionsCH_allCov_sex <- read.capthist(captfile = 'CAPTURE   
FILES/secr_CAPS_nosex_noForest2012.csv', trapfile = 'TRAP FILES/SECR_TRAPS_INPUT_ALL_noforest2012.csv', detector = 'count', fmt = 'trapID', covnames = 'sex',  trapcovnames=c('/Hft','Altitude', 'Anthro_biome', 'Ruggedness','Globecover_2009', 'Veg_NDVIAnn','SA_PA_2015','VegMap2009_biome',  'VegMap2009_Bioregion', 'SEDAC_PopDensity2015', 'LANDCOVER_WC', 'SLOPE_WC_percentage','bio8_46','bio7_46','bio2_46','bio9_46', 'bio17_46','bio15_46','bio19_46','bio6_46','bio4_46'))



Code: Select all
secr.fit(PP_ALLregionsCH_allCov_sex, model=list(D~session, g0 ~ b), trace = FALSE, buffer=15000)

(OR)
Code: Select all
secr.fit(PP_ALLregionsCH_allCov_sex, model = g0 ~ b, trace = FALSE, buffer=15000)


Unfortunately I am getting the error message:

Code: Select all
Error in secr.fit(PP_ALLregionsCH_allCov, model = list(D ~ session, g0 ~  :
  'verify' found errors in 'capthist' argument
In addition: Warning message:
In verify.capthist(capthist, report = 1) :
  Levels of factor covariate(s) differ between sessions


If I remove all mention of sex and the column from my input file I no longer get the “Levels of factor covariate(s) differ between sessions” warning, but I am still stuck with the error:
Code: Select all
Error in secr.fit(PP_ALLregionsCH_allCov, model = g0 ~ b, trace = FALSE,  :
  'verify' found errors in 'capthist' argument


I haven’t tried to split the genders into sessions because I’ve had to already divide my data into many sessions across many different regional surveys conducted. Is there a way to get around this?
I would really like to have sex used within the analysis, but I have absolutely struggled with trying all the different script options from the manuals and from other questions within this forum. Can you see what I must be doing wrong or what I have overlooked?

No matter what I do, I can't seem to shake these errors and warnings. I'd greatly appreciate your thoughts!

Best,
Carolyn (I remembered this time :D )
cdevens226
 
Posts: 10
Joined: Mon Mar 03, 2014 1:10 pm
Location: Pretoria, South Africa

Re: incorporating sex into analysis

Postby murray.efford » Wed Jul 01, 2015 10:30 am

Hello Carolyn
An integrity check (verify) is run both on input (read.capthist) and by default when you fit a model (secr.fit). That is what generates the messages you are seeing,and where you should start to troubleshoot. You can also run it with verify(PP_ALLregionsCH_allCov_sex).

I cannot tell what is going on. You report errors from secr.fit but not read.capthist, when I would also have expected 'verify' errors to appear there. I am suspicious about the slash in '/Hft' - was that intended? I wonder if NA in your csv file is read as the character value 'NA' rather than a missing value NA - I don't use csv files much myself. (This would be a problem if Sex was missing in some sessions and not others).

Dealing with factors can be a pain, especially that insistence they have the same levels in each session. At worst you may need to manually set the levels of a factor to be the same in each session, perhaps using something like
Code: Select all
for (i in 1:length(PP_ALLregionsCH_allCov_sex))
    levels(covariates(PP_ALLregionsCH_allCov_sex[[i]])$Sex) <- c('F','M')

if, for example, some sessions had leopards of only one sex. Then check with
Code: Select all
sapply(PP_ALLregionsCH_allCov_sex, function(x) levels(covariates(x)$Sex))


As a last resort, suppress error messages from verify by setting verify = FALSE in your secr.fit call.

I haven’t tried to split the genders into sessions because I’ve had to already divide my data into many sessions across many different regional surveys conducted. Is there a way to get around this?

Not quite sure what you mean here. The 'hcov' mechanism should be sufficient.
Murray
murray.efford
 
Posts: 712
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: incorporating sex into analysis

Postby cdevens226 » Wed Jul 08, 2015 12:20 pm

Hi Murray,
Thanks so much for the speedy reply.

Nope, I am only getting the 'verify' errors when I run secr.fit and not read.capthist!

I managed to get it to run with sex using your
Code: Select all
sapply(PP_ALLregionsCH_allCov_sex, function(x) levels(covariates(x)$Sex))
and then
Code: Select all
secr.fit(PP_ALLregionsCH_allCov_sex, model=list(D~session, g0 ~ b), hcov = 'Sex', CL=FALSE, trace = FALSE, buffer=1000, verify = FALSE)
and got D results!! (though these are the models or buffer I will use.. just a test)

What I meant by
I haven’t tried to split the genders into sessions because I’ve had to already divide my data into many sessions across many different regional surveys conducted. Is there a way to get around this?
was that I saw in the secr manual under modelling sex differences the instruction:
Use full likelihood (CL = FALSE) and separate data for the two sexes as different sessions (most easily, by coding ‘female’ or ‘male’ in the first column of the capture file read with read.capthist). Then include a group term ‘session’ in relevant model formulae (e.g., g0 ∼ session).

..but I already need to organize my sessions a different way due to my data set's several surveys over several regions.

Question... how bad is it to run the secr.fit with suppressed error messages using verify = False? I have been doing this and it seems to be running fine (as far as D given). Though, I recognize that the error is occurring for a reason and don't want to simply be suppress it and causing issues with the output!?

Thanks in advance for any further help!!! ...Also did you manage to have time to look at my other question that I posted about unpacking the results? I'd be so grateful if you'd be able to give me any thoughts on this topic as well!

All the best,
Carolyn
cdevens226
 
Posts: 10
Joined: Mon Mar 03, 2014 1:10 pm
Location: Pretoria, South Africa

Re: incorporating sex into analysis

Postby murray.efford » Fri Jul 10, 2015 2:45 pm

how bad is it to run the secr.fit with suppressed error messages using verify = False?

there isn't a general black and white answer to this. Often 'secr.fit' will do the sensible thing (e.g., if you have more than one capture in a single-catch trap it won't matter because the multi-catch likelihood is used anyway). I guess you want to know specifically about the factor levels error, but I can't remember off the top of my head precisely if and when this sort of inconsistency in the data messes up the model fit - probably OK 75% of the time (not a very useful statement!). If the difference is because a 'sex' factor sometimes has an added 3rd level ('F', 'M', and 'NA' for 'missing' where the last level follows the others when ordered alphabetically) then I would not expect a problem.
Murray
murray.efford
 
Posts: 712
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand


Return to analysis help

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest