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

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat, 05 May 2007 05:47:30 -0400

Using the builtin data frame CO2 this regresses uptake, which is variable number 5, against each consecutive pair of variables:

for(i in 1:3) {

   idx <- c(i, i+1, 5)
   print(lm(uptake ~., CO2[idx]))
}

On 5/5/07, Victor Bennett <bennett_at_haas.berkeley.edu> wrote:
> 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.
>



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 - 09:50:27 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 - 12:31:22 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.