How to extract p-values from lmekin objects in coxme package
r
Solution
It took me ages of searching to figure this out, but I noticed a lot of other similar questions without proper answers, so I wanted to answer this.
You use:
library(coxme)
print(model)
- Note it is important to load the coxme package beforehand or it will not work.
I've also noticed a lot of posts about how to extract the p-value from `lmekin` objects, or how to extract the p-value from coxme objects in general. I wrote this function, which is based on the `coxme:::print.coxme` function code (to view code type `coxme:::print.coxme` directly into R). `print` calculates p-values on the fly - this function allows the extraction of p-values and saves them to an object.
Note that `mod` is your model, eg. `mod <- lmekin(y~x+a+b)` Use `print(mod)` to double check that the tables match.
extract_coxme_table <- function (mod){
beta <- mod$coefficients$fixed
nvar <- length(beta)
nfrail <- nrow(mod$var) - nvar
se <- sqrt(diag(mod$var)[nfrail + 1:nvar])
z<- round(beta/se, 2)
p<- signif(1 - pchisq((beta/se)^2, 1), 2)
table=data.frame(cbind(beta,se,z,p))
return(table)
}
Problem
I want to be able to view the p-values for the lmekin object produced by the coxme package. eg. ``` model= lmekin(formula = height ~ score + sex + age + (1 | IID), data = phenotype_df, varlist = kinship_matrix) ``` I tried: ``` summary(model) coef(summary(model)) summary(model$coefficient$fixed) fixef(model)/ sqrt(diag(vcov(model)) #(Calculates Z-scores but not p-values) ``` But these did not work. So how do I view the p-values for this linear mixed model?