Extracting density estimates from model

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

Extracting density estimates from model

Postby Bryan Hamilton » Wed May 13, 2015 8:22 pm

Hello,

How can I extract the real parameter estimates from an secr model? Using predict() the estimates show up, but I would like get the density estimates as a vector or dataframe.

Code: Select all
secr0 <- secr.fit(CH, model = list(D~g, g0~1, sigma~1) ,groups='Loc_Name',buffer = 150,
                  trace = FALSE,start = list(D=1, g0=0.2, sigma=25) ) # null model

Code: Select all
> predict(secr0)
$`session = 2004, g = HabRest_Mam_001`
       link   estimate SE.estimate        lcl        ucl
D       log  0.1508709  0.04601342  0.0840915  0.2706818
g0    logit  0.3868580  0.09752501  0.2198769  0.5854789
sigma   log 42.9765246  2.03021032 39.1780622 47.1432623

$`session = 2004, g = HabRest_Mam_002`
       link    estimate SE.estimate          lcl         ucl
D       log  0.01257256  0.01655166  0.001761587  0.08973115
g0    logit  0.38685802  0.09752501  0.219876950  0.58547885
sigma   log 42.97652456  2.03021032 39.178062200 47.14326231


What I want to do is extract the estimates of the real parameters (D,g0,and sigma) from the model secr0.

Thanks for any help.
Bryan Hamilton
 
Posts: 111
Joined: Thu Jun 15, 2006 11:36 am
Location: Great Basin National Park

Re: Extracting density estimates from model

Postby murray.efford » Wed May 13, 2015 8:31 pm

This is one of those tricky R subscripting questions. In your case you have both sessions (years) and groups within sessions. Assuming 2 groups:

I use something like
Code: Select all
pred <- predict(secr0)
D <- sapply(pred, '[[', 'D', 'estimate') ## a 'long, thin' vector of densities
matrix(D, ncol = 2, byrow = TRUE) ## a 2-col matrix, one row per year, one col per group

See if this works. The 'sapply' function applies the list extraction operator [[ to each component of pred in turn, extracting in this case the cell with the density estimate. 'byrow=TRUE' tells 'matrix' that the values are coming in row-dominant order instead of the default column-dominant order.

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

Re: Extracting density estimates from model

Postby Bryan Hamilton » Thu May 14, 2015 10:43 am

That worked wonderfully. Thank you.

I'm not very familiar with lists and matrix subsetting, having worked mainly with dataframes. I should probably work on that.
Bryan Hamilton
 
Posts: 111
Joined: Thu Jun 15, 2006 11:36 am
Location: Great Basin National Park


Return to analysis help

Who is online

Users browsing this forum: No registered users and 1 guest

cron