Re: [R] Fitting model with varying number of predictors

2005-11-18 Thread Prof Brian Ripley
On Fri, 18 Nov 2005, Juni Joshi wrote: I need to fit a number of models with different number of predictors in each model. Say for example, I have three predictors: x1, x2, x3 and I want to fit three models: lm(y~x1+x2) lm(y~x2+x3) lm(y~x1+x2+x3) Instead of typing

Re: [R] Fitting model with varying number of predictors

2005-11-18 Thread Yves Magliulo
try : my_formula = as.formula(paste(y~,xxx)) lm(my_formula) note that you can play with substr in paste to change your formula paste(y~,substr(xxx,1,5)) [1] y~ x1+x2 paste(y~,substr(xxx,4,8)) [1] y~ x2+x3 furthermore, with 10 predictors x1 x2 ...x10 for instence, you can create 2 array of

Re: [R] Fitting model with varying number of predictors

2005-11-18 Thread Frank E Harrell Jr
Juni Joshi wrote: I need to fit a number of models with different number of predictors in each model. Say for example, I have three predictors: x1, x2, x3 and I want to fit three models: lm(y~x1+x2) lm(y~x2+x3) lm(y~x1+x2+x3) Stepwise variable selection has so many

[R] Fitting model with varying number of predictors

2005-11-17 Thread Juni Joshi
I need to fit a number of models with different number of predictors in each model. Say for example, I have three predictors: x1, x2, x3 and I want to fit three models: lm(y~x1+x2) lm(y~x2+x3) lm(y~x1+x2+x3) Instead of typing all models, what I want is to create a

Re: [R] Fitting model with varying number of predictors

2005-11-17 Thread Gabor Grothendieck
Try this: x - data.frame(x1 = x1, x2 = x2, x3 = x3) lm(y ~., x[,1:2]) lm(y ~., x[,2:3]) lm(y ~., x[,1:3]) On 11/18/05, Juni Joshi [EMAIL PROTECTED] wrote: I need to fit a number of models with different number of predictors in each model. Say for example, I have three predictors: