r - How to extract dependent variable names from for-looped glms object to use as titles -
i making barplots of corresponding model coefficients derrived lapply function applied for-looped multi-glm object. take lwanimovesubdat data set makes facile explication in code below:
models.lw <- list() ivnames.lw <- paste(names(subset(lwanimovsubdat[,c(1:6)], select = -c(4))), collapse = ' + ') dvnames.lw <- paste(names(lwanimovsubdat[7:17]), sep = ',') (y in dvnames.lw){ form <- as.formula(paste(y, "~", ivnames.lw)) models.lw[[y]] <- glm(form, data = lwanimovsubdat) } (var in models.lw) { dev.new() barplot(coef(var)) }
how add titles above barplots without getting things messed up. tried following , not work:
main = names(models.lw)
please help!
main = names(models.lw) doesn't work because refers names of of models. if change barplot code follows, iterate through names of models , reference models based on names, should work.
for (var in names(models.lw)){ dev.new() barplot(coef(models.lw[var][[1]]), main = var) }
Comments
Post a Comment