Skip to content
Back to formatted view

Raw Message

Message-ID: <CAHmzXO76GO7xDZiEHx1g8abi3dzeU24ZGogP9a04kzPyzZXkLg@mail.gmail.com>
Date: 2014-08-27T20:11:12Z
From: Gang Chen
Subject: Issue with formula conversion
In-Reply-To: <27AD3578-A2A6-4E7B-BBB6-C8B3DC9A4198@comcast.net>

Good point!

Here is an example:

library(nlme)
fm <- lme(yield ~ nitro, data=Oats, random=list(Block=pdComSymm(~Variety-1)))

Now the problem I'm facing is that the following part

pdComSymm(~Variety-1)

is read in as a string of characters from an external source:

ranEff <- 'pdComSymm(~Variety-1)'

The following

(ranEff1 <- as.formula(ranEff))
~Variety - 1

is not what I want. Even though

fm <- lme(yield ~ nitro, data=Oats, random=list(Block=pdCompSymm(ranEff1)))

works, I don't know the 'pdCompSymm' part in advance and would like to
make the process automatic.

On Wed, Aug 27, 2014 at 3:49 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> On Aug 27, 2014, at 12:44 PM, Gang Chen wrote:
>
>> Thanks for the help! However, I just need to get
>>
>> pdCompSymm(~1 + Age)
>
> That's not a formula in the R sense of the word. You should do a better job of posting a use case. Perhaps you want an expression?
>
> --
> David.
>>
>> without a tilde (~) at the beginning.
>>
>> On Wed, Aug 27, 2014 at 3:34 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>>>
>>> On Aug 27, 2014, at 11:19 AM, Gang Chen wrote:
>>>
>>>> A random effect formulation for R package nlme is read in as a string
>>>> of characters from an input file:
>>>>
>>>> ranEff <- "pdCompSymm(~1+Age)"
>>>>
>>>> I need to convert 'ranEff' to a formula class. However, as shown below:
>>>>
>>>>> as.formula(ranEff)
>>>> ~1 + Age
>>>>
>>>> the "pdCompSymm" is lost in the conversion. Any solutions?
>>>
>>> as.formula(paste("~",ranEff))
>>> ~pdCompSymm(~1 + Age)
>>> --
>>>
>>> David Winsemius
>>> Alameda, CA, USA
>>>
>
> David Winsemius
> Alameda, CA, USA
>