0

I have 7 1-factor logistic regression models that I have fitted using GLM (stored in model1 to model7). For each model, I want to extract their coefficient and store in "coeffs" vector well as the p-value to be stored in "p-values" vector. I tried using loops in R but I am getting the following error-Error: $ operator is invalid for atomic vectors. How can I loop this to get vectors having coefficient and p-values for each model? Here is my code-


coeffs<-c()
p_values<-c()

for (x in c(model1,model2,model3,model4,model5,model6,model7)) {
  coeffs <- summary(x)$coefficients[2,1]
  p_values <- summary(x)$coefficients[2,4]
  
  
}

yash471994
  • 63
  • 7

1 Answers1

1

Put the models in a list and use sapply/lapply to extract the values.

model_list <- list(model1,model2,model3,model4,model5,model6,model7)

t(sapply(model_list, function(x) {
  tmp <- summary(x)
  c(coeffs = tmp$coefficients[2,1], p_values = tmp$coefficients[2,4])
}))
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213