NJKlappstein / hmmSSF

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

Extracting transition matrix parameters #4

Closed IlhemB closed 1 month ago

IlhemB commented 1 month ago

Hello,

I am currently trying to extract the parameters of the transition matrix. However, I am encountering an issue where the values obtained frommod$par$tpm do not appear to be probabilities.

Could you please guide me on the correct method to extract this information?

Thank you for your assistance.

Best regards, Ilhem

NJKlappstein commented 1 month ago

Hi Ilhem,

Thanks for the message. The parameters are coefficients associated with the transition probabilities, not the transition probabilities themselves (we denote these $\alpha_0, \alpha_1, \dots, \alpha_p$). The coefficients are transformed by an (inverse) multinomial logit link function to get the transition probabilities, as described in Equations 9-10 of Klappstein et al. (2023). Do you have covariates on the transition probabilities?

I think there is some inconsistency in our naming and presentation, which might be confusing. I will think about how to improve this (and update here when there are relevant changes), but hopefully this helps for now.

Best, Natasha

IlhemB commented 1 month ago

Hi Natasha,

Thank you very much for the explanation. I now have a better understanding of the coefficients.

I would like to save the values of the transition matrix, print(mod) only displays them. Is there a way to save these values directly?

Thank you for your assistance.

Best, Ilhem

NJKlappstein commented 1 month ago

Glad that helped.

Yes, ultimately print(mod) is using predict_tpm() under the hood. So, assuming you have no covariates, you can calculate the TPM for any row of data (here, we're using the first row, but this is arbitrary):

tpm <- predict_tpm(mod = mod, new_data = mod$args$data[1,], return_CI = TRUE).

This will give the TPM that is printed in the model summary. You can use return_CI = FALSE if you don't want/need the 95% CIs. Let me know if you run into any issues.

Natasha

IlhemB commented 1 month ago

Hi Natasha,

The function predict_tpm works perfectly. Thank you very much.

Best, Ilhem