I am re-writting an earlier question I had which was deleted for lack of details.
I would like to extract the p-value of a number of regression that I am running with a loop and have the p-values stored for each of the independant variable as a list. My issue is with storing the new lists correctly. You will find below the code, the sample data and the expected results.
Many thanks!
ind_var <- list(c("Man","Below_Master","Worker","Rural", "Less_than_26"))
depending_var <- list(c("Q1","Q2","Q3","Q4", "Q5", "Q6"))
x <- list()
for (var_p in depending_var) {
{ for (var in ind_var)
x1 <- lm(paste(var, "~", var_p), data = Ech_final_nom_SD, weights = pond)
x[[var_p]] <- summary(x1)$coefficients[,4] #Where shit hits the fan
}
}
Here is the sample data:
| ID | Man | Below_Master | Worker | Rural | Less than 26 | Q1 | Q2 | Q3 | Q4 | Q5 | Q6 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 0 | 0 | 1 | 4 | 3 | 1 | 2 | 2 | 1 |
| 2 | 0 | 0 | 0 | 1 | 1 | 2 | 2 | 2 | 2 | 3 | 1 |
| 3 | 0 | 1 | 0 | 0 | 1 | 4 | 3 | 1 | 1 | 3 | 1 |
| 4 | 0 | 0 | 1 | 0 | 0 | 1 | 4 | 1 | 2 | 3 | 1 |
| 5 | 0 | 1 | 1 | 0 | 1 | 4 | 3 | 4 | 2 | 3 | 2 |
| 6 | 1 | 0 | 1 | 1 | 1 | 3 | 2 | 1 | 2 | 2 | 2 |
| 7 | 0 | 1 | 0 | 0 | 0 | 3 | 3 | 3 | 2 | 1 | 2 |
| 8 | 1 | 0 | 0 | 0 | 1 | 3 | 3 | 1 | 4 | 1 | 3 |
| 9 | 1 | 0 | 0 | 1 | 1 | 2 | 3 | 1 | 2 | 2 | 3 |
| 10 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 2 | 3 |
Expected results (with different p-values for all) :
x_Man <- list(c("0.0234","0.9894", "0.0045", "0.9892", "0.0229", "0.0254","0.0894", "0.0047", "0.2392", "0.0029"))
x_Below_Master <- list(c("0.0434","0.9854", "0.0545", "0.0092", "0.0729", "0.0254","0.0894", "0.0047", "0.2392", "0.0029"))
x_Worker <- list(c("0.0234","0.9894", "0.0045", "0.9892", "0.0229", "0.0254","0.0894", "0.0047", "0.2392", "0.0029"))
x_Rural <- list(c("0.0234","0.9894", "0.0045", "0.9892", "0.0229", "0.0254","0.0894", "0.0047", "0.2392", "0.0029"))
x_Less_than_26 <- list(c("0.0234","0.9894", "0.0045", "0.9892", "0.0229", "0.0254","0.0894", "0.0047", "0.2392", "0.0029"))