NJKlappstein / hmmSSF

R package to fit state-switching step selection functions (HMM-SSFs) with covariate-dependent transition probabilities
3 stars 0 forks source link

local_decoding #5

Open SnowpeaSoho opened 2 months ago

SnowpeaSoho commented 2 months ago

Hi there I am having good success exploring fitting various hmmSSF models, however one function local_decoding() - which works fine in the archived manuscript code lodged on zenodo - is throwing an error?

states <- viterbi_decoding(mod = mod4) # works fine head(states) [1] 2 2 2 2 2 2

local_decoding(mod4) # throws error Error: Not compatible with requested type: [type=NULL; target=double].

mod4 # hmmSSF object Negative log-likelihood: 29444 Convergence code: 0

SSF model: ~step + log(step) + cos(angle) + cov1 mle low upp step.S1 -0.386 -0.410 -0.362 log(step).S1 0.302 0.189 0.415 cos(angle).S1 -0.066 -0.116 -0.015 cov1.S1 -3.404 -6.219 -0.590 step.S2 -0.102 -0.112 -0.092 log(step).S2 1.043 0.715 1.371 cos(angle).S2 2.409 2.127 2.692 cov1.S2 -3.476 -7.482 0.530

TPM model: ~1 S1 S2 S1 0.962 0.038 S2 0.160 0.840

str(mod4) # model object structure List of 3 $ par :List of 2 ..$ ssf: num [1:4, 1:2] -0.3859 0.3021 -0.0656 -3.4043 -0.1021 ... .. ..- attr(, "dimnames")=List of 2 .. .. ..$ : chr [1:4] "step" "log(step)" "cos(angle)" "cov1" .. .. ..$ : chr [1:2] "S1" "S2" ..$ tpm: num [1, 1:2] -3.22 -1.66 .. ..- attr(, "dimnames")=List of 2 .. .. ..$ : chr "(Intercept)" .. .. ..$ : chr [1:2] "1>2" "2>1" $ fit :List of 6 ..$ par : num [1:10] -0.3859 0.3021 -0.0656 -3.4043 -0.1021 ... ..$ value : num 29444 ..$ counts : Named int [1:2] 1265 NA .. ..- attr(, "names")= chr [1:2] "function" "gradient" ..$ convergence: int 0 ..$ message : NULL ..$ hessian : num [1:10, 1:10] 44152.64 8004.6 -479.71 -8.33 -11244.11 ... $ args:List of 6 ..$ tpm_formula:Class 'formula' language ~1 .. .. ..- attr(, ".Environment")=<environment: 0x0000025b94777278> ..$ ssf_formula:Class 'formula' language ~step + log(step) + cos(angle) + cov1 .. .. ..- attr(*, ".Environment")= ..$ data :'data.frame': 134946 obs. of 11 variables: .. ..$ ID : chr [1:134946] "112724" "112724" "112724" "112724" ... .. ..$ stratum: Factor w/ 2646 levels "96382.2-3","96382.2-4",..: 65 65 65 65 65 65 65 65 65 65 ... .. ..$ obs : num [1:134946] 1 0 0 0 0 0 0 0 0 0 ... .. ..$ x : num [1:134946] -3111 -3165 -3130 -3157 -3125 ... .. ..$ y : num [1:134946] 598 658 636 647 644 ... .. ..$ time : POSIXct[1:134946], format: "2016-11-09 10:00:00" "2016-11-09 10:00:00" ... .. ..$ step : num [1:134946] 43.78 44.64 5.75 32.77 4.87 ... .. ..$ angle : num [1:134946] 0.00452 -2.30602 -1.34323 -2.11292 2.83458 ... .. ..$ w : num [1:134946] 2.43e-05 4.61e-06 1.20e-03 1.73e-05 7.26e-04 ... .. ..$ cov1 : num [1:134946] 1.14 1.2 1.18 1.2 1.18 ... .. ..$ doy_c2 : num [1:134946] 0.281 0.281 0.281 0.281 0.281 ... ..$ n_states : num 2 ..$ ssf_cov : chr [1:4] "step" "log(step)" "cos(angle)" "cov1" ..$ tpm_cov : chr "(Intercept)"

  • attr(*, "class")= chr [1:2] "hmmSSF" "list"
TheoMichelot commented 2 months ago

Hi Sophie,

Thanks for finding this, it should be fixed now (see commit cd104c5). Can you please check and let us know if you still get an error?

Théo