[R] dynamically specifying regressors/RHS variables in a regression

From: Victor Bennett <bennett_at_haas.berkeley.edu>
Date: Fri, 04 May 2007 22:24:20 -0700

Does anyone know if there is a way to specify regressors dynamically rather than explicitly?

More specifically, I have a data set in "long format" that details a number of individuals and their responses to a question (which can be positive, negative, or no answer). Each individual answers as many questions as they want, so there are a different number of rows per individual.

For each number of questions, I want to run a logit on all the individuals who saw that many questions, predicting whether they choose to answer anymore afterwards by their choices on the earlier questions.

the second logit would look like
answered_only_2~answer_1_pos+answer_1_neg+answer_2_pos+answer_2_neg

This will result in over 100 regressions, with different numbers of RHS variables. I'd like to iterate over the sequence of numbers and run a logit for each, but I can't find any means for dynamically generating the RHS variable from an array, or vector. The only way I can think of to write the function would still require the same number of RHS variables in each regression.

Is there a way to dynamically generate the right hand side?



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 05 May 2007 - 05:34:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 05 May 2007 - 11:31:49 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.