Starts argument in occu() - with random effects

543 views
Skip to first unread message

Maddy Uetrecht

unread,
Jul 8, 2021, 7:02:51 PM7/8/21
to unmarked
Hello,

I need to add starting values to the parameters in my occu() models. How can I tell which order to enter starting values if I'm including a random effect in my models?

For example, here's one of the models:
bear59 <- occu(~ ped + scale.veg + start.jday.scale ~ (1 | Trail) + avg.ped + avg.biker + scale.distance, bear.um, starts = starts)

And here's what I get from coef(bear59):
> coef(bear59)
           psi(Int)        psi(avg.ped)      psi(avg.biker) psi(scale.distance)              p(Int)              p(ped)        p(scale.veg) p(start.jday.scale) 
          0.6969433           2.6714447           3.8643894           0.6051945          -3.7084103          -5.0477263           0.4271411           0.8424586

There are 8 coefficients listed, so I tried making a list of 8 starting values:
starts <- c(0,0,0,0,0,0,0,0)

Then I got this error message:
"Error in fit_TMB("tmb_occu", tmb_dat, tmb_param, rand_ef, starts = starts,  : 
  The number of starting values should be 9"

I'm guessing the 9th value is for the random effect in the model, but since it's not listed in the coefficients, how do I know which value in "starts" corresponds to each coefficient? I will need to test different starting values for each coefficient, so I can't just add a 9th "0" to the example vector.

Thanks!
Maddy

Ken Kellner

unread,
Jul 8, 2021, 7:17:29 PM7/8/21
to unmarked
Hi Maddy,

You're right that the last value is the SD for the random effect. You can see the proper order with

bear59@TMB$par

which should return a vector with names something like

beta_state beta_state beta_state beta_state lsigma_state beta_det beta_det beta_det beta_det

Not super informative, but basically it's the four occupancy (state) fixed effect parameters (intercept + 3 covs) followed by the log(SD) of trail, followed by the four fixed effects for detection. This is the general order that TMB will always follow. However, I was experimenting a bit and it doesn't look like I've sent custom initial values to TMB properly. I'll see if I can put together a quick fix. To be honest though I have rarely seen a situation where changing the initial values helped much in unmarked outside of distance sampling models with certain key functions.

Ken

Ken Kellner

unread,
Jul 8, 2021, 9:06:51 PM7/8/21
to unmarked
Setting initial values for models with random effects should work properly now in the dev version of unmarked. Probably the easiest way to install it is with the following command:

install.packages("unmarked", repos="https://kenkellner.com/R")

After fitting a model without custom starts,  look at

bear59@TMB$starts_order

for the correct order of starting values. I added that because it seems like bear59@TMB$par is sometimes not the correct order.

Ken

Lain E. Pardo

unread,
Jul 10, 2021, 1:39:04 PM7/10/21
to unma...@googlegroups.com
Dear Ken,

thanks to Maddy´s question I just get to know that we can now include random effects with occu, nice, thanks!. I tried to check it out and the model runs ok, but I could not test for model fit using mb.gof.test.

The message I receive is:
Error in checkForRemoteErrors(val) :
  3 nodes produced errors; first error: The number of starting values should be 9
In addition: Warning messages:
1: In if (grepl(":|/", char)) { :
  the condition has length > 1 and only the first element will be used
2: In if (grepl(":|/", char)) { :
  the condition has length > 1 and only the first element will be used
3: In if (grepl(":|/", char)) { :
  the condition has length > 1 and only the first element will be used
4: In if (grepl(":|/", char)) { :
  the condition has length > 1 and only the first element will be used
5: In if (grepl(":|/", char)) { :
  the condition has length > 1 and only the first element will be used
6: In if (grepl(":|/", char)) { :
  the condition has length > 1 and only the first element will be used

I ran this code, using both starting values and no starting values and I have the same issue in both models when trying the assess model fit

global_out <-occu(~Flash + Cam.Days + Tree.Cover.Cam
                              ~ Human.Density.Buffer  + Agriculture.Buffer +  Build.up.Buffer +
                    (1 | Season), starts = starts, data.umf)
starts <- c(0,0,0,0,0,0,0,0,0)

Could you please assist?
thanks much,
L

--
You received this message because you are subscribed to the Google Groups "unmarked" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/unmarked/2fefae5f-a401-498e-91f9-a4e8aa16a7c6n%40googlegroups.com.


--

Postdoctoral Research Fellow

Wildlife Ecology Lab,

School of Natural Resource Management

Nelson Mandela University

George Campus, South Africa

Mobile: +27-0762599325

Lain....@Mandela.ac.za

Ken Kellner

unread,
Jul 10, 2021, 3:30:48 PM7/10/21
to unmarked
There was a bug in parboot for random effects models that also affected mb.gof.test. Should be fixed now (hopefully along with those warnings). To install new dev version:

install.packages("unmarked", repos="https://kenkellner.com/R")
library(unmarked)
sessionInfo() # check you have unmarked_1.1.1.9005
# your model

Thanks everyone for your patience with all these random-effects related bugs. 

Ken

Maddy Uetrecht

unread,
Jul 14, 2021, 9:28:42 PM7/14/21
to unmarked
Hi Ken,

Thank you so much, this is really helpful! I tried using bear59@TMB$par and it worked. However, I don't think the dev version of unmarked is installing properly - I ran the install.packages() command, and my sessionInfo() still shows version 1.1.1. And when I run bear59@TMB$starts_order it returns "NULL." Is there another way I can try to install the dev version?

Thanks,
Maddy

Ken Kellner

unread,
Jul 15, 2021, 11:32:16 AM7/15/21
to unmarked
Hi Maddy,

Before running the commands in my previous email, did you completely restart your R session? If not, the old version of unmarked is probably still loaded.

Ken

Patrick

unread,
Aug 10, 2021, 5:37:21 PM8/10/21
to unmarked
Hi Ken,

I'm using pcount() with a random effect and have a similar error when assessing fit using parboot():

Error in fit_TMB("tmb_pcount", tmb_dat, tmb_param, rand_ef, starts = starts,  : 
  The number of starting values should be 10
In addition: Warning messages:
1: In rbinom(M * J, size = rep(N, each = J), prob = pvec) : NAs produced
2: In rbinom(M * J, size = rep(N, each = J), prob = pvec) : NAs produced

I attempted to install unmarked_1.1.1.9005 as you suggested above, but similarly to Maddy, sessionInfo() still shows unmarked_1.1.1 (I made sure to restart R). Is there another way to install the dev version? Or perhaps there is another way to address this error message?


I have an additional question:

It appears that when I run more complex models I receive the following warning messages:

Warning messages:
1: Using formula(x) is deprecated when x is a character vector of length > 1.
  Consider formula(paste(x, collapse = " ")) instead. 
2: In if (grepl(":|/", char)) { :
  the condition has length > 1 and only the first element will be used

The model outputs from these models don't seem particularly unusual. Should I be concerned about these warnings? If so, do you have any ideas for how to avoid them?

Thanks so much!
Patrick

Ken Kellner

unread,
Aug 10, 2021, 6:04:41 PM8/10/21
to unmarked
Hi Patrick,

Can you try uninstalling your current version of unmarked completely before installing the new one, and then checking the version again?

The updated version should fix both of your issues.

Ken

Patrick

unread,
Aug 11, 2021, 1:14:32 PM8/11/21
to unmarked
Hi Ken,

Unfortunately, when I uninstall it still shows unmarked_1.1.1. I don't seem to be able to install the dev version unless another version is already installed. When I do this, I now receive the following message at the end of the installation process:

ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin18/8.2.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [unmarked.so] Error 1
ERROR: compilation failed for package ‘unmarked’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/unmarked’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/unmarked’
Warning in install.packages :
  installation of package ‘unmarked’ had non-zero exit status

The downloaded source packages are in
‘/private/var/folders/9_/wnf52jvx1gn85cb32bhyp1w40000gn/T/RtmpUKWYun/downloaded_packages’



As well as an earlier message:

Warning message:
In checkMatrixPackageVersion() : Package version inconsistency detected.
TMB was built with Matrix version 1.3.2
Current Matrix version is 1.2.18
Please re-install 'TMB' from source using install.packages('TMB', type = 'source') or ask CRAN for a binary version of 'TMB' matching CRAN's 'Matrix' package

I'm not sure why this second message continues to appear since it is the version that was automatically downloaded with unmarked.

Thanks,
Patrick


Ken Kellner

unread,
Aug 11, 2021, 2:29:41 PM8/11/21
to unmarked
Hi Patrick,

I see now that you are on a Mac, I've not been able to test my suggested installation approach on Macs (I don't have one handy) so I guess I'm not surprised it didn't work.

Maybe you could try using the package devtools approach instead?

1. restart R
2. Install Xcode from the Mac App Store (sorry I can't be more specific on how to do this, maybe someone else can help?). This is needed to compile the package.
3. install 'devtools' library if you don't have it
4. run the following code:

library(devtools)
install_github("rbchan/unmarked")

5. Check again for version number.

Ken

Patrick

unread,
Oct 29, 2021, 1:03:49 PM10/29/21
to unmarked
Hi Ken,

Apologies for the delayed follow-up. Unfortunately, I'm still having issues. I installed Xcode, ran your code, and received the following: 

In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadillo.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadilloForward.h:48:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo:23:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/compiler_check.hpp:72:4: error: "*** C++11 compiler required; enable C++11 mode in your compiler, or use an earlier version of Armadillo"
  #error "*** C++11 compiler required; enable C++11 mode in your compiler, or use an earlier version of Armadillo"
   ^
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadillo.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadilloForward.h:48:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo:87:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:152:12: error: unknown type name 'constexpr'
    static constexpr bool is_row  = false;
           ^
#.......
#(a number of other messages similar to the last two lines above)
#.......

/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:214:12: error: unknown type name 'constexpr'
    static constexpr bool is_xvec = false;
           ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘unmarked’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/unmarked’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/unmarked’
Warning message:
In i.p(...) :
  installation of package ‘/var/folders/9_/wnf52jvx1gn85cb32bhyp1w40000gn/T//RtmpKCdNAA/file3cb35f1914f6/unmarked_1.1.1.9010.tar.gz’ had non-zero exit status



Any ideas for how to proceed?

Thanks so much!

Patrick

Jim Baldwin

unread,
Nov 27, 2021, 2:07:46 AM11/27/21
to unma...@googlegroups.com
For an occu output object named fm in unmarked 1.1.1 I'm getting names of the parameters in fm@TMB$par as you mention above but all of the values are (always) zeros.  However, the values do appear in fm@opt$par in the correct order with the value of the random effect parameter being the log of the standard deviation.  Am I looking in the wrong place?

Thanks,

Jim


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

Ken Kellner

unread,
Nov 27, 2021, 12:37:37 PM11/27/21
to unmarked
If you fit fm with the dev version (1.1.1.9xxx) then the correct order for the initial values should be in fm@TMB$starts_order.
This extra info isn't yet available in the CRAN version.
Reply all
Reply to author
Forward
0 new messages