CecileProust-Lima / lcmm

R package lcmm
https://CecileProust-Lima.github.io/lcmm/
48 stars 13 forks source link

Extracting estimates, standard errors and p-values of fixed effects in the class-membership model #218

Closed noellevanbiljon closed 9 months ago

noellevanbiljon commented 9 months ago

Hi,

I am trying to extract the estimates, standard errors and p-values associated with the fixed effects in the class-membership model.

I can visualise this output when calling for the summary of an lcmm object, however if I store this object only the "fixed effects in the longitudinal model" output is stored. I know estimates can be extracted using the estimates() function, however I also want to access the standard errors and p-values.

Alternatively I can access this information using the following call: capture.output(summary(lcmm_ouput)), however, this extracts each line of output as a string which causes other problems.

Is there a function I am missing that will allow easy access to the estimates, standard errors and p-values of fixed effects in the class-membership model?

Many Thanks for all the help!

VivianePhilipps commented 9 months ago

Hi,

we don't have any function that returns these 3 results for the class-membership parameters, but as you noticed you get the parameters with the estimates function. The vcov function returns the variances, and the p-value can be computed with the WaldMult function. Here's the code:

n <- model$N[1] # number of coef in the classmb model

coef <- estimates(model)[1:n] se <- sqrt(diag(vcov(model)))[1:n] pval <- sapply(1:n, function(k) WaldMult(model, pos=k)[2])

cbind(coef, se, pval) #should be the same as in the summary

Viviane

noellevanbiljon commented 9 months ago

Hi Viviane, thanks so much this works perfectly! Really appreciate the assistance.