Page 1 of 1

Predicting Dsurface with groups results in all NA

PostPosted: Fri Sep 19, 2014 2:03 pm
by jnwaite
Hello,

I am trying to predict density surfaces from full likelihood models that contain groups (e.g., sex). I am modeling density as a function of elevation (covariate "z" in my habitat mask). Everything works great if I omit the groups term from the model:

Code: Select all
> fit.1.1 <- secr.fit(captHist, model=list(D~z, g0~1, sigma~1), mask=maskElev, trace=TRUE)
> surf.1.1 <- predictDsurface(fit.1.1)
> head(surf.1.1)
         x        y          D.0
1 853204.9 424468.1 0.0001354751
2 853704.9 424468.1 0.0003083124
3 854204.9 424468.1 0.0002361373
4 862204.9 424468.1 0.0006862312
5 862704.9 424468.1 0.0006563962
6 863204.9 424468.1 0.0008017443


When I include the groups term, the models run just fine and give (what I believe to be) reasonable results, but all the predicted values in the Dsurface are NA. This also happens when I use any of the built-in variables (x, y, xy, x2, and y2).

Code: Select all
> fit.g.g <- secr.fit(captHist, model=list(D~z, g0~g, sigma~g), mask=maskElev, groups="sex", trace=TRUE)
> surf.g.g <- predictDsurface(fit.g.g)
> head(surf.g.g)
         x        y D.F D.M
1 853204.9 424468.1  NA  NA
2 853704.9 424468.1  NA  NA
3 854204.9 424468.1  NA  NA
4 862204.9 424468.1  NA  NA
5 862704.9 424468.1  NA  NA
6 863204.9 424468.1  NA  NA


Incidentally, if I keep the groups term but just model density as D~1, then predictDsurface works as expected (constant density estimates for each group across all points in the mask). I can also predict a Dsurface from a hybrid mixture model when setting hcov="sex", but I end up with just a single surface rather than group-specific surfaces and I am really interested in looking at that spatial variation of various groups (especially age class, once we have more data).

So, what all of this boils down to is: can I get group-specific Dsurfaces?

I realize I haven't provide much information here, in terms of my study design and data structure, so please let me know if more information is needed here.

Thanks!

Re: Predicting Dsurface with groups results in all NA

PostPosted: Fri Sep 19, 2014 2:29 pm
by murray.efford
Hi
The documentation promises this, but the code seems not to be delivering... I'll look into it later today. (This is good timing, as I'm re-writing the density surface documentation for a new version release next week).
Murray

Re: Predicting Dsurface with groups results in all NA

PostPosted: Sat Sep 20, 2014 10:40 pm
by murray.efford
More on this...
1. Yes there was a bug, now fixed. (I think you could probably have got output from groups with integer labels, but not alphanumeric labels)
2. As 'g' does not appear in your model for D, the estimated density is the same for both groups (this is easily fixed with e.g., D ~ z + g).
3. If your model is totally group-specific (D~z+g, g0~g, sigma~g) then it might be quicker and clearer to split into separate capthist objects. For example, I am working on an example like this -
Code: Select all
MF <- split(OVpossumCH, covariates(OVpossumCH)$Sex)
fit.D6FM <- lapply(MF, secr.fit, mask = ovmask, model = D ~ 1))
par(mfrow = c(1,2))
surface6FM <- lapply(fit.D6FM, predictDsurface)
The result here is an R 'list' of Dsurfaces. For what it's worth, I'd also say that even respectable SECR datasets can be pathetically inadequate when it comes to fitting (e.g., polynomial) density trend surfaces, and you are probably on stronger ground with a single spatial predictor like elevation.
Murray

Re: Predicting Dsurface with groups results in all NA

PostPosted: Mon Sep 22, 2014 2:00 pm
by jnwaite
Thank you for the help--I look forward to the updated release next week. In the meantime, I think I'll try changing the sex covariates to numerical to see what happens.

Re: Predicting Dsurface with groups results in all NA

PostPosted: Mon Sep 22, 2014 5:33 pm
by murray.efford
Jason
You shouldn't have to wait long - the new version 2.9.0 has just been submitted to CRAN - it takes 1-2 days to generate the Windows binary and distribute it to mirror sites.
Murray

Re: Predicting Dsurface with groups results in all NA

PostPosted: Fri Sep 27, 2019 10:48 am
by mouse
There may be some issue on my end but I am experience the same exact problem Jason had. When the model contains a group covariate (sex) and predictDsurface produces only NAs in the D.F and D.M columns. It does work normally when run with a model excluding groups.

model = list(D ~ g, g0 ~ g + t, sigma ~ g), groups = "sex",...

x y D.F D.M
48 349081.5 4537529 NA NA
49 350094.5 4537529 NA NA
50 351107.4 4537529 NA NA
51 352120.3 4537529 NA NA

Thanks for the help,

Ryan

Re: Predicting Dsurface with groups results in all NA

PostPosted: Sat Sep 28, 2019 12:47 am
by murray.efford
It would be annoying if the bug has returned... I don't have time to check right now. Meantime as your model is fully group-specific you can follow the earlier advice and split the dataset in two.

Re: Predicting Dsurface with groups results in all NA

PostPosted: Mon Sep 30, 2019 5:17 pm
by mouse
Hopefully the bug has not returned, I'll wait to hear what you find. Appreciate the help.