Parameter fitting stratified model openCR 2.2.1

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

Parameter fitting stratified model openCR 2.2.1

Postby butterphi » Thu Jan 20, 2022 11:10 am

I ran a non-spatial model (type='JSSAbCL') with a stratified dataset in openCR 2.2.1. The first part of the output looks good but there is an error when fitting (real) parameters.

My code is:
Code: Select all
# stratification
CH_strat <- stratify(list(CH_M2019, CH_M2020, CH_M2021, CH_TI2019, CH_TI2020, CH_TI2021), intervals = list(int_M2019, int_M2020, int_M2021, int_TI2019, int_TI2020, int_TI2021), bytraps=T)
# model building
JSSA1 <- openCR.fit(CH_strat, type = 'JSSAbCL', model = list(phi~1, p~1, b~stratum*sex), distribution="binomial", stratified=TRUE)
# inference
JSSA1


The code leads to the following output:
[...]
Variance-covariance matrix of beta parameters
p phi b
p 0.01141 -0.01721 0.00777
phi -0.01721 0.08037 -0.01990
b 0.00777 -0.01990 0.05438

Fitted (real) parameters evaluated at base levels of covariates
Error in matrix(x, nrow = nsess[j]) :
invalid 'nrow' value (too large or NA)
In addition: Warning message:
In matrix(x, nrow = nsess[j]) :
data length [15] is not a sub-multiple or multiple of the number of rows [19]


I can't figure out, what causes the problem and I'd be very happy to hear your ideas/experiences.
butterphi
 
Posts: 9
Joined: Tue Nov 02, 2021 9:00 am

Re: Parameter fitting stratified model openCR 2.2.1

Postby murray.efford » Thu Jan 20, 2022 5:12 pm

That section of the output is generated by predict() so you should get the same messages with predict(JSSA1). That isn't helpful in itself, but the good news is that the problem in predict() most likely comes from a coding mistake in the automatic generation of 'newdata' with function makeNewData() (e.g., makeNewData(JSSA1)).

Until I can get around to fixing this, you may be able to construct your own newdata dataframe as input for predict.

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

Re: Parameter fitting stratified model openCR 2.2.1

Postby butterphi » Wed Jan 26, 2022 10:21 am

Thank you very much for your fast reply, Murray!

I figured out that my problem using 'predict' is the different number of sessions in different strata of my dataset. However, I do not manage to pass a proper 'newdata'. A list with one dataframe for each stratum does not work, right? Could you suggest any workaround?

After subsetting my data (I used only those strata with equal session numbers), I still have an issue with derived(). Is there another way to extract the size of the superpopulation (per stratum)?

Many thanks for your help!
butterphi
 
Posts: 9
Joined: Tue Nov 02, 2021 9:00 am

Re: Parameter fitting stratified model openCR 2.2.1

Postby murray.efford » Wed Jan 26, 2022 5:41 pm

It should be possible to have different numbers of sessions per stratum.
'newdata' should be a single dataframe, not a list of dataframes.
I would be interested to see what you get from makeNewData(JSSA1), or maybe just send me a copy of JSSA1 offline.
Murray
murray.efford
 
Posts: 686
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Parameter fitting stratified model openCR 2.2.1

Postby murray.efford » Fri Jan 28, 2022 4:11 pm

Thanks for sending an example privately. makeNewData() was not the problem. In openCR <=2.2.2, predict() didn't work when the number of sessions varied among strata, and and derived() did not work at all with stratified models. These bugs have been fixed in the working version 2.2.3 that can be accessed as a Windows binary here or installed from the GitHub source if you have the necessary tools.
murray.efford
 
Posts: 686
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand


Return to analysis help

Who is online

Users browsing this forum: No registered users and 5 guests

cron