sex spesific sigma or det

445 views
Skip to first unread message

Lourens Swanepoel

unread,
Jun 2, 2018, 2:29:34 AM6/2/18
to oSCR
oSCR users,
I have the following model (model=list(D~session,p0~sex,sig~1); question is how do I get 'det' from get.real?

this is what I do now:
# Get real estimates
  nd <- data.frame(session=factor(1:3))
  ot.dens = as.data.frame (get.real(model = m0R1, type = "det",newdata = nd))

But, it seems to need sex in the nd?

Error in eval(predvars, data, env) : object 'sex' not found

I am unsure as how to add sex to nd, if I  indeed have to do that?

any suggestions much appreciated.
Thanks
Lourens

Chris Sutherland

unread,
Jun 2, 2018, 6:59:19 AM6/2/18
to Lourens Swanepoel, oSCR
Hi lourens,

This should get you what you want:
nd <- data.frame(session=factor(rep(1:3,2))), sex=rep(c(0,1),each=3))



--
You received this message because you are subscribed to the Google Groups "oSCR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to oscr_package...@googlegroups.com.
To post to this group, send email to oscr_p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/oscr_package/b4c9064c-1faf-43bb-aab5-e3b738de34ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lourens Swanepoel

unread,
Jun 2, 2018, 8:11:22 AM6/2/18
to oSCR
Thanks Chris, I now get the following error? any thoughts? Density and Sigma works, just Sex?

Error in eval(g) : object 't.beta.sex' not found

L

David Bernasconi

unread,
Mar 17, 2020, 4:44:21 PM3/17/20
to oSCR
I'm having the same  issue. was this resolved?

Chris Sutherland

unread,
Mar 17, 2020, 5:04:50 PM3/17/20
to oscr_p...@googlegroups.com

Hi David,

 

Do either of the following resolve the issue:

 

nd <- data.frame(session=factor(1).sex=c(0,1))

nd <- data.frame(session=factor(1).sex=factor(c(0,1)))

 

Chris

--

You received this message because you are subscribed to the Google Groups "oSCR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to oscr_package...@googlegroups.com.

Manolo García

unread,
Nov 18, 2020, 9:56:43 PM11/18/20
to oSCR
Hi,
I'm still having the issue. Was it resolved?
Best,

Chris Sutherland

unread,
Nov 24, 2020, 5:46:42 AM11/24/20
to oscr_p...@googlegroups.com

Hello Manolo,

 

Is you provide an example of the snippet of code you are using, I can pinpoint the issue. It seems that when I coded up the get.real() function, the passing of sex info requires slightly different structure depending on type. That frustrating (for me when using it, so I can imagine its frustrating for y’all too!). It likely that, in the new year, I will have more time to devote to ironing out these wrinkles. In the meantime, here is a set of instructions that should help everyone generate newdata objects that work with the different ‘types’ in get.real():

 

nd1 <- data.frame(session=factor(1), sex=c(0,1))

nd2 <- data.frame(session=factor(1), sex=factor(c(0,1)))

nd3 <- data.frame(session=factor(1), sex=c("m","f"))

nd4 <- data.frame(session=factor(1), sex=factor(c("m","f")))

 

 

Density (type = “dens”):

  • All of these work

 

Detection (type = “det”):

  • nd2 works
  • nd1, nd3, and nd4 do not work

 

Sigma (type = “sig”):

  • nd2 works
  • nd1, nd3, and nd4 do not work

 

Hope that helps! Its certainly helped me pinpoint where the fix lies! If you are interested in seeing this in practice, here is the script I used to test it out using the ocelot data:

 

library(oSCR)

data("ocelot")

 

ocelot.dat <- data2oscr(edf = edf1,

                        tdf = list(tdf1),

                        sess.col = 1,

                        id.col = 2,

                        occ.col = 3,

                        trap.col = 4,

                        sex.col = 5,

                        sex.nacode = "U",

                        K = 44,   

                        ntraps = 21,

                        tdf.sep = "/")

 

ocelot.sf <- ocelot.dat$scrFrame

ocelot.ss <- make.ssDF(ocelot.sf, buffer = 2500, res = 250)

 

msex <- oSCR.fit(list(~1, ~sex, ~sex), ocelot.sf, ocelot.ss, trimS=2500) #takes 5 mins!

 

nd1 <- data.frame(session=factor(1), sex=c(0,1))

nd2 <- data.frame(session=factor(1), sex=factor(c(0,1)))

nd3 <- data.frame(session=factor(1), sex=c("m","f"))

nd4 <- data.frame(session=factor(1), sex=factor(c("m","f")))

 

get.real(msex,type = "dens", newdata = nd1)

get.real(msex,type = "dens", newdata = nd2)

get.real(msex,type = "dens", newdata = nd3)

get.real(msex,type = "dens", newdata = nd4)

 

get.real(msex,type = "det",  newdata = nd1)

get.real(msex,type = "det",  newdata = nd2)

get.real(msex,type = "det",  newdata = nd3)

get.real(msex,type = "det",  newdata = nd4)

 

get.real(msex,type = "sig",  newdata = nd1)

get.real(msex,type = "sig",  newdata = nd2)

get.real(msex,type = "sig",  newdata = nd3)

get.real(msex,type = "sig",  newdata = nd4)

 

 

Chris

Ursa Flezar

unread,
Jan 5, 2022, 4:27:20 PM1/5/22
to oSCR
Hi everyone,

I found this a very useful thread. I managed to do the same steps in my analysis to some extent however, I got stuck with the following.
My best model for estimating densities of lynx in Dinarics (EU) includes "sex" (0,1) and "trap location type" (1,2,3) as covariates on detection probability. After trying several options, I still cannot extract the values for detection probabilities. Following your suggestions above, my best try was:

nd3 <- data.frame(session=factor(1), sex=factor(c(0,0,0,1,1,1)), location_type=factor(c(1,2,3,1,2,3)))
pred.det_slm2 <- get.real(model=scr3_sex_lt_mask, type="det", newdata = nd3)

But I get an error:
Error in eval(g., envir) : object 't.beta.location_type2' not found

In fact, I don't even manage to extract the mean detection probability however, this is another question; should I even report and interpret the mean p0 if my best model tells me it's changing with sex and trap location type?

Thanks in advance for you reply and thanks for keeping this lifesaving group active!

Best,
Urša

Chris Sutherland

unread,
Jan 7, 2022, 7:05:40 AM1/7/22
to oSCR
Hi  Urša, 

Not sure I can say what's happening here without a bit of digging. I wonder if you would be willing to share the fitted model object with a script that produces the error. I should be able to figure it out quite quickly from there.

Chris  



Daniel Linden

unread,
Jan 7, 2022, 7:19:32 AM1/7/22
to oSCR
My guess is that the model thought trap "location_type" was numeric so it didn't estimate an effect for the 2 other types and instead estimated a single slope.  In that case, "t.beta.location_type2" would not exist in the model object.

I would make sure that "location_type" is indeed a factor before fitting the model.

As for reporting the mean, I agree it's value is limited when categorical effects are included in the model.  But note that the intercept for p0 is not indicating the mean across everything, rather it's the estimate of detection for the reference category (or categories with multiple covariates).  In your case, once "location_type" is a factor, p0 would be for sex=0 and location_type=1.

Hope this helps, Urša!

Chris Sutherland

unread,
Jan 7, 2022, 7:32:17 AM1/7/22
to oSCR
Yes! Dan is right.

If you look at the model summary (just type the model name into the R console), you might see that there is a single parameter for location type (t.beta.location_type) suggesting a signal slope for a continuous variable. If it is a factor in the model fitting, then there will be two parameters: t.beta.location_type2 and t.beta.location_type3 (type one is the reference level and is therefore p0). 

Hope that helps.

Chris (but really all Dan 😁)

Ursa Flezar

unread,
Jan 11, 2022, 3:02:46 AM1/11/22
to oscr_p...@googlegroups.com
Ah! Thanks a lot to both! :)
I will check the structure of the location_type, re-run the models if necessary and get back to you if there's any other questions left. I feel revising the parameter output interpretation wound not hurt.

By the way, is it possible to test the interaction of sex and location_type, or is it just one or the other? I'm thinking about this from a GLM point of view where you can test the effect of different factors (separated by a "+" sign), or their interaction (separated by a "*" sign) on a chosen variable.

Thanks again.

/Urša

Ursa Flezar

unread,
Jan 15, 2022, 3:27:59 PM1/15/22
to oSCR
It worked!

Thanks again!
p0_sex_loctype.png

Marco Salvatori

unread,
Sep 6, 2024, 8:58:39 AM9/6/24
to oSCR
Hi all,

I have a similar question as this one Ursa asked, that I see didn't receive any answer, so I try posting it again.

I am running a model in oSCR and have two types of traps and I would like to understand if males and females are detected differently by the two kinds of traps. Therefore the ideal would be including an interaction between sex and trap type in the detection probability submodel, but when I tried inserting the "trap_type*sex" structure I get an error. Does anybody know if and how this can be done?

I am aware that for the sex-structured likelihood used by oSCR covariates in the density submodel can show different slopes to males and females without the need of explicit interaction, but this doesn't seem to be the case for the detection probability submodel, since when I try the simpler additive model "trap_type+sex" the coefficient for the levels of trap type are the same for males and females.

Any help is greatly appreciated

Best

Marco Salvatori

Jeffrey Royle

unread,
Sep 6, 2024, 10:22:12 AM9/6/24
to oscr_p...@googlegroups.com
hi Marco,
 Interacting trap covariate effects with sex isn't implemented in the model formulas because of the way sex is handled in the likelihood construction because the likelihood evaluation requires computing a bit when sex is unknown. In principle this could be done I think but we haven't implemented it.
 One idea is you can create multiple sessions based on sex (M in one session, F in the other session) and then you might be able to do it.  I'm curious if anyone out there has solved this problem in a similar way?
regards
andy


Reply all
Reply to author
Forward
0 new messages