Session and habitat spesific density estimates

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

Session and habitat spesific density estimates

Postby lourens » Sun Mar 13, 2016 11:59 am

Hi All,
I have 3 seasons camera trapping, and 3 habitat types. I found that habitat type affected g0, and that density vary by season. So I fitted the following model:
Code: Select all
Mdens.habitat <- secr.fit(CH, model = c(D ~  session, g0~Habitat), mask=mask.sec, detectfn=1)

I want to extract session & habitat specific values of density; using
Code: Select all
predict(Mdens.habitat)

I get the following:
> predict(Mdens.habitat)
$`session = Summer2015, Habitat = grassandwet`
link estimate SE.estimate lcl ucl
D log 7.645846e-03 0.001513766 5.206159e-03 0.01122881
g0 logit 1.598026e-01 0.032962603 1.051871e-01 0.23531821
sigma log 3.228419e+02 34.473128615 2.620330e+02 397.76256485
z log 3.275634e+00 0.237019248 2.843049e+00 3.77403989

$`session = Winter2014, Habitat = grassandwet`
link estimate SE.estimate lcl ucl
D log 4.272679e-03 0.001077598 2.626168e-03 6.951491e-03
g0 logit 1.598026e-01 0.032962603 1.051871e-01 2.353182e-01
sigma log 3.228419e+02 34.473128615 2.620330e+02 3.977626e+02
z log 3.275634e+00 0.237019248 2.843049e+00 3.774040e+00

$`session = Winter2015, Habitat = grassandwet`
link estimate SE.estimate lcl ucl
D log 7.056588e-03 0.001449783 0.00473717 0.01051164
g0 logit 1.598026e-01 0.032962603 0.10518708 0.23531821
sigma log 3.228419e+02 34.473128615 262.03297273 397.76256485
z log 3.275634e+00 0.237019248 2.84304880 3.77403989

So I use the following for session/habitat specific density estimates
Code: Select all
predict(Mdens.habitat,newdata =expand.grid(Habitat=factor(c("grassandwet","grass","wet")),session = c("Winter2014","Summer2015","Winter2015")))

But this gives me
Error in mat %*% beta[indx] : non-conformable arguments


What am I missing in the code, or am I missing something
Any help would be appreciated
Lourens
lourens
 
Posts: 10
Joined: Wed Nov 02, 2011 8:06 am

Re: Session and habitat spesific density estimates

Postby murray.efford » Sun Mar 13, 2016 3:56 pm

Hi Lourens
I cannot see anything wrong with your code, so I'm thinking it must be a problem with your particular data and model. I'm willing to troubleshoot if you send a binary (Rdata) file 'save'd with the fitted model. The ordering of factor levels is always a worry, but that doesn't seem to be the issue.
Murray
murray.efford
 
Posts: 686
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Session and habitat spesific density estimates

Postby lourens » Sun Mar 13, 2016 5:28 pm

Murray,
Thanks for the offer, will contact you offline.
Lourens
lourens
 
Posts: 10
Joined: Wed Nov 02, 2011 8:06 am

Re: Session and habitat spesific density estimates

Postby murray.efford » Sun Mar 13, 2016 8:28 pm

This turned out to be a factor level problem. Habitat is a factor with 4 levels:
Code: Select all
 levels(covariates(traps(CH)[[1]])$Habitat)
[1] "disturbed"   "grass"       "grassandwet" "wet"     

The 'disturbed' level happened to be the first and reference level, so it doesn't appear specifically in the named coefficients. To predict from this model you have to specify a factor with the same levels, e.g.
Code: Select all
predict(Mdens.habitat,newdata = expand.grid(
    Habitat = factor(c("disturbed", "grass", "grassandwet","wet")),
    session = c("Winter2014","Summer2015","Winter2015")))
## or
predict(Mdens.habitat,newdata = expand.grid(
    Habitat = factor(c("grass","wet"), levels =
        c("disturbed","grass","grassandwet","wet")),
    session = c("Winter2014","Summer2015","Winter2015")))

(By default, levels get placed in alphabetical order. I never know when this is going to trip me up, so I try to conform whenever possible).
Murray
murray.efford
 
Posts: 686
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Session and habitat spesific density estimates

Postby lourens » Mon Mar 14, 2016 1:40 am

Murray,
Thanks so much, I feel a bit silly not to have picked this up.
Lourens
lourens
 
Posts: 10
Joined: Wed Nov 02, 2011 8:06 am


Return to analysis help

Who is online

Users browsing this forum: No registered users and 12 guests