Home > database >  I am trying to produce adjusted p-values for 119 models that were produced with lapply in R
I am trying to produce adjusted p-values for 119 models that were produced with lapply in R

Time:11-28

I produced 119 logistic regression models with lapply. I then used lapply again to get the coefficients and p-values in a summary format

#Model 1
#looping through the different metabolites to produce over 100 logistic 
regression models. For hpresponse1. Minimally adjusted
response1minadj<-lapply(metabolite.names, function(X) 
glm(as.formula(paste0("hpresponse1~",X, "  age   BMIfactor")),
                                           data=df, family="binomial"))
response1minadj
#getting the effects sizes and p-values- hpresponse1, minimally adjusted
results1<-lapply(response1minadj, function(p) coef(summary(p)))
results1

Now I want adjusted p-values with p.adjust. I thought I could change the summary of results into their own separate dataframes, name the columns and then use p.adjust on the column I named "pvalue"

#changing the results into separate dataframes
results1 = lapply(results1, function (d) as.data.frame(d))

#renaming the columns
results =lapply(results1, function(b) colnames(b) = c("beta","SE", "zvalue" 
,"pvalue"))

However, the column names change doesn't seem to work as the following syntax produces "null"

colnames(results1)

Is there another way to accomplish my goal of getting adjusted p-values for all 119 models? Or is there a way to get my syntax to work?

CodePudding user response:

The function in lapply returns column names, not the updated value of b.

Try this instead:

results = lapply(results1, function(b){colnames(b) = c("beta", "SE", "zvalue", "pvalue"); return(b);})

CodePudding user response:

For getting the p-value from the model, you can use:

p_values <- coef(summary(model))[, "Pr(>|t|)"] 

For the whole list of p-values, or add [1/2/3/4/...] for a specific p-value at the end of the code.

Then you could possibly do p.adjust on p_values, e.g.,

p_adjusted <- p.adjust(p_values)

So to first get the p-value from the model, and then do p.adjust on that p-value

  • Related