[R] problem with get() inside of lme()

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Wed May 16 14:59:06 CEST 2012


You can achieve that with a combination of as.formula and paste.

library(nlme)
data(petrol, package = "MASS")
lme(as.formula(paste(Y.VAR, "~EP")), random= ~1|No, data=petrol)

Best regards,

Thierry

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx op inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey


-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org] Namens chuck.01
Verzonden: zaterdag 12 mei 2012 23:28
Aan: r-help op r-project.org
Onderwerp: Re: [R] problem with get() inside of lme()

Here is an example:
library(nlme)
library(lme4)
library(MASS)

data(petrol)

# a variable for one of the columns in petrol Y.VAR <- "Y"

# This works:
lmer(get(Y.VAR)~EP +(1|No), data=petrol)

# This doesn't:
lme(get(Y.VAR)~EP, random= ~1|No, data=petrol)

# but this does:
lme(Y~EP, random= ~1|No, data=petrol)

I'd really like to use the variable... again, this is inside a function.

Any idea how to solve this.
Thanks for your time and expertise,
Chuck




chuck.01 wrote
>
> please note that I edited the original message to say:
>
>> length(with(new3, perm.score))==length(with(new3, get(TRAIT1)))
> [1] TRUE
>
>
>
>
>
> chuck.01 wrote
>>
>> Hi,
>>  The following lines of code are inside of a function, where  "TRAIT1" is
>> a function variable calling a column-name inside of the data.frame
>> "new3".
>>
>> This works just fine:
>>
>> m2 <- lmer(get(TRAIT1) ~ perm.score + (1|site), data=new3)
>>
>> but this will not work:
>>
>> m3 <- lme(get(TRAIT1) ~ perm.score , random= ~1|site, data=new3)
>>
>> I get the following error:
>>
>> Error in model.frame.default(formula = ~TRAIT1 + perm.score + site, data
>> = list( :
>>   variable lengths differ (found for 'perm.score')
>>
>> it seems to be putting TRAIT1 on the left side of the equation, and if I
>> am wrong about that, the different lengths from the error is still not
>> true:
>>
>>> length(with(new3, perm.score))==length(with(new3, get(TRAIT1)))
>> [1] TRUE
>>
>> Any ideas on either what is going on, or how I can fix this?
>>
>> ** I'm not including example data, or function because I am hoping it is
>> not needed **
>> Please let me know if I am wrong.
>>
>


--
View this message in context: http://r.789695.n4.nabble.com/problem-with-get-inside-of-lme-tp4629360p4629588.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help op r-project.org 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.
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.



More information about the R-help mailing list