[R] question about formula for lm
Mike Lawrence
Mike.Lawrence at DAL.CA
Sat Jun 16 13:26:29 CEST 2007
Yet another solution:
with(X,lm(get(Ytext)~Xvar))
On 14-Jun-07, at 5:18 PM, Greg Snow wrote:
>
> Try:
>
>> lm( formula( paste( Ytext, '~ Xvar' ) ), data=X)
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.snow at intermountainmail.org
> (801) 408-8111
>
>
>
>> -----Original Message-----
>> From: r-help-bounces at stat.math.ethz.ch
>> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Pedro Mardones
>> Sent: Thursday, June 14, 2007 1:14 PM
>> To: R-help at stat.math.ethz.ch
>> Subject: [R] question about formula for lm
>>
>> Dear all;
>>
>> Is there any way to make this to work?:
>>
>> .x<-rnorm(50,10,3)
>> .y<-.x+rnorm(50,0,1)
>>
>> X<-data.frame(.x,.y)
>> colnames(X)<-c("Xvar","Yvar")
>>
>> Ytext<-"Yvar"
>>
>> lm(Ytext~Xvar,data=X) # doesn't run
>>
>> lm(Yvar~Xvar,data=X) # does run
>>
>> The main idea is to use Ytext as input in a function, so you
>> just type "Yvar" and the model should fit....
>> Also, I need to avoid the expression X$Yvar~X$Xvar
>>
>> Thanks for any idea
>>
>> PM
>>
>> ______________________________________________
>> 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.
--
Mike Lawrence
Graduate Student, Department of Psychology, Dalhousie University
Website: http://myweb.dal.ca/mc973993
Public calendar: http://icalx.com/public/informavore/Public
"The road to wisdom? Well, it's plain and simple to express:
Err and err and err again, but less and less and less."
- Piet Hein
More information about the R-help
mailing list