Hello,
I think I am having an issue with calling derived() from the openCR package. I had experienced a suite of issues using the function on different models, and after trying a bunch of different things to resolve the problems, and exploring the source codes, I think they all stemmed from an inability to properly call the right derived() function. This is what happens when I try to specify the package for use of derived() on an openCR model:
> openCR::derived(test)
Error: 'derived' is not an exported object from 'namespace:openCR'
> secr::derived(test)
Total number observed 191
Parameters in model p, phi, f, superN
Superpopulation size 297.5006
Session-specific counts and estimates:
session sex t n R m r z time p phi f superN b lambda gamma kappa N
1 F 1 63 63 0 29 0 0 0.1852 0.9661 3.997e-15 297.5 7.605e-01 0.9661 NA NA 226.3
2 F 2 80 80 18 38 11 10 0.1852 0.9661 2.838e-01 NA 2.247e-14 1.2499 1.0000 0.7872 160.2
3 F 3 70 70 33 17 16 11 0.1852 0.9661 9.992e-16 NA 2.395e-01 0.9661 0.7729 0.8939 226.0
4 F 4 62 62 33 0 0 20 0.1852 NA NA NA 7.017e-15 NA 1.0000 0.7036 165.6
This is confusing to me, as the output using secr::derived() looks like it is appropriate for an openCR model, but with some bugs, described below. I have tried several times to uninstall and reinstall openCR and Rcpp (I thought the issue might be with the makegkcpp function), and have explored the source codes, but have been unable to resolve the issue. I was able to replicate results for derived() from the openCR source codes for the JSSAsecrbCL model type, as derived() doesn't work at all for those model types, but the openCR.esa() function did not work properly either, so I got stalled when trying to derive D:
>openCR.esa(fitsecrb[[1]])
Error in makegkcpp(as.integer(nrow(realparval0)), as.integer(k), as.integer(m), :
Not a matrix.
Below is a description of some errors that occurred when I use derived() on openCR models:
It seems a little buggy when used on spatial openCR models (you need to call the estimates directly from the output list to see them, the last kappa doesn't get estimated though it does for non-spatial models, and it doesn't work with JSSAsecrbCL models - it produces the following error:
> derived(fitsecrb[[1]])
Error in makegkcpp(as.integer(nrow(realparval0)), as.integer(k), as.integer(m), :
Not a matrix.).
It seems to have less obvious issues with non-spatial models, but upon closer examination of the results, there might be issues there too. I have fit a JSSAf model type using the following parameterization:
p~sex, phi~sex, f~t+sex, N~t
and also used RMark to fit a similar type of model:
p~sex, phi~sex, f~t+sex, f0~t (RMark RDPdfcClosed, which uses the Pradel formulation instead)
The outputs from openCR, both real and derived are below, followed by the results from RMark. I understand that both phi and f are scaled for the user-specified time intervals (for these results, 10, 1, and 9 for primary sessions).
But why is phi the same using the predict() and derived() functions, but f is not? It looks like f is somehow scaled incorrectly, as it is the same in the second primary session, when there is a time interval of 1 afterward, but much smaller for the others. Could this be affecting N estimates, as the openCR derived estimates are very different from the derived estimates using RMark?
Note, I have an uneven number of secondary sampling occasions in my second primary session for some of my transects, and did not incorporate this into my RMark analysis, but my capthist traps object does have an appropriate usage matrix. This might be why there are small discrepancies in estimates of phi and f between the two packages.
openCR results:
session sex estimate SE.estimate lcl ucl
capnew13 1 F 0.9660548 0.009549452 0.9414601 0.9805301
capnew14 2 F 0.9660548 0.009549452 0.9414601 0.9805301
capnew14PF 3 F 0.9660548 0.009549452 0.9414601 0.9805301
capnew15 4 F NA NA NA NA
> predict(test)$f
session sex estimate SE.estimate lcl ucl
capnew13 1 F 0.04436629 0.012595210 0.02543339 0.07739305
capnew14 2 F 0.28383438 0.096723275 0.14554522 0.55351838
capnew14PF 3 F 0.02659445 0.009059893 0.01363997 0.05185237
capnew15 4 F NA NA NA NA
> derived(test)
Total number observed 191
Parameters in model p, phi, f, superN
Superpopulation size 297.5006
Session-specific counts and estimates:
session sex t n R m r z time p phi f superN b lambda gamma kappa N
1 F 1 63 63 0 29 0 0 0.1852 0.9661 3.997e-15 297.5 7.605e-01 0.9661 NA NA 226.3
2 F 2 80 80 18 38 11 10 0.1852 0.9661 2.838e-01 NA 2.247e-14 1.2499 1.0000 0.7872 160.2
3 F 3 70 70 33 17 16 11 0.1852 0.9661 9.992e-16 NA 2.395e-01 0.9661 0.7729 0.8939 226.0
4 F 4 62 62 33 0 0 20 0.1852 NA NA NA 7.017e-15 NA 1.0000 0.7036 165.6
RMark results:
> Robustmodels3[[112]]$results$real
estimate se lcl ucl fixed note
Phi gF a0 t1 0.9647136 0.0094949 0.9405676 0.9792659
Phi gM a0 t1 0.8698507 0.0285431 0.8030513 0.9163535
f gF a0 t1 0.0432405 0.0138039 0.0229605 0.0799671
f gF a10 t11 0.3360935 0.1175158 0.1527746 0.5869810
f gF a11 t12 0.0252802 0.0094636 0.0120701 0.0521843
f gM a0 t1 0.1336951 0.0342360 0.0795819 0.2159697
f gM a10 t11 0.6335197 0.1490309 0.3294282 0.8588129
f gM a11 t12 0.0813585 0.0297191 0.0390380 0.1618318
p gF s1 t1 0.1928667 0.0145030 0.1660209 0.2228933
p gM s1 t1 0.1275172 0.0151713 0.1006192 0.1603238
f0 gF a0 s1 t0 29.7639490 6.6478939 19.3142140 45.8673940
f0 gF a0 s11 t0 20.2068670 4.9865618 12.5468890 32.5433240
f0 gF a0 s12 t0 48.8236310 9.6297038 33.2920040 71.6011840
f0 gF a0 s21 t0 42.8767310 8.8691548 28.7069070 64.0408290
> Robustmodels3[[112]]$results$derived
$`N Population Size`
estimate lcl ucl
F 1 70.76395 60.31421 86.86739 total N for each period = ~ 122, 120, 166, 146
F 2 73.20687 65.54689 85.54332
F 3 95.82363 80.29200 118.60118
F 4 85.87673 71.70691 107.04083
M 5 51.76395 41.31421 67.86739
M 6 47.20687 39.54689 59.54332
M 7 71.82363 56.29200 94.60118
M 8 61.87673 47.70691 83.04083
Thanks very much for taking the time to read through all of that, and I appreciate any guidance in advance.
Best,
Jennifer