[R-sig-ME] contrasts among simple effects

James Henson jfhenson1 at gmail.com
Mon Oct 19 21:24:05 CEST 2015


Dear Russell,

Your assistance is appreciated. However, the code below returns an error
message. Maybe my model is inappropriate. It was necessary to remove the
ordered statement [ordered(time)], because apparently with the ordered
statement lsmeans did not read time as a factor.

library("nlme")

# with AR1 variance/covariance structure

heartRate$time <- factor(heartRate$time)

model2a <- lme(HR ~ drug*time, random =~1|person, correlation
=corAR1(form=~1|person), data = heartRate)

summary(model2a)

library("lsmeans")

anova(model2a)

lsm <- lsmeans(model2a, ~ drug|time)

lsm

Error in format.default(nm[j], width = nchar(m[1, j]), just = "left") :

  4 arguments passed to .Internal(nchar) which requires 3



pairs(lsm)

pairs(lsm, by = "drug")



The Using lsmeans tutorial (Oct 9, 2015) illustrates the usefulness of the
lsmeans package.

Best regards,

James F. Henson

On Mon, Oct 19, 2015 at 1:39 AM, Thierry Onkelinx <thierry.onkelinx at inbo.be>
wrote:

> Dear James,
>
> Please keep the mailing list in cc. Most likely someone else would have
> told you that the errors are due to a syntax error. You want lme(HR ~
> drug*ordered(time), random =~1|person, correlation =
> corAR1(form=~time|person), data = heartRate)
>
> Best regards,
>
> 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
>
> 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
>
> 2015-10-16 19:07 GMT+02:00 James Henson <jfhenson1 at gmail.com>:
>
>> Dear Thierry,
>>
>> Thank you for the counsel. However, my perplexity persists.  Many
>> variations of adding 'corAR1(form = ~time|person)' return an error
>> message.  Some of these variations are below.
>>
>> model2b <- lme(HR ~ drug*ordered(time), random =~1|person, correlation
>> =corAR1(, form=~1|person) =corAR1(, form=~time|person), data = heartRate)
>>
>> Error: unexpected '=' in "model2b <- lme(HR ~ drug*ordered(time), random
>> =~1|person, correlation =corAR1(, form=~1|person) ="
>>
>>
>>
>> > model2b <- lme(HR ~ drug*ordered(time), random =~1|person, correlation
>> =corAR1(, form=~1|person) corAR1(, form=~time|person), data = heartRate)
>>
>> Error: unexpected symbol in "model2b <- lme(HR ~ drug*ordered(time),
>> random =~1|person, correlation =corAR1(, form=~1|person) corAR1"
>>
>>
>>
>> model2b <- lme(HR ~ drug*ordered(time), random =~1|person, correlation
>> =corAR1(, form=~1|person), =corAR1(, form=~time|person), data = heartRate)
>>
>> Error: unexpected '=' in "model2b <- lme(HR ~ drug*ordered(time), random
>> =~1|person, correlation =corAR1(, form=~1|person), ="
>>
>>
>>
>> model2b <- lme(HR ~ drug*ordered(time), random =~1|person, correlation
>> =corAR1(, form=~time|person), data = heartRate)
>>
>> Error in structure(res, levels = lv, names = nm, class = "factor") :
>> 'names' attribute [72] must be the same length as the vector [0]
>>
>>
>>
>> model2b <- lme(HR ~ drug*ordered(time), random =~1|person, correlation
>> =corAR1(, form=~1|person, time|person), data = heartRate)
>>
>> Error in time | person :  operations are possible only for numeric,
>> logical or complex types
>>
>>
>>
>> model2b <- lme(HR ~ drug*ordered(time), random =~1|person, correlation
>> =corAR1(, form=~1|person, form=~time|person), data = heartRate)
>>
>> Error in corAR1(, form = ~1 | person, form = ~time | person) :  formal
>> argument "form" matched by multiple actual arguments
>>
>>
>>
>> model2b <- lme(HR ~ drug*ordered(time), random =~1|person, correlation
>> =corAR1(, form=~1|person), correlation= corAR1(, form=~time|person), data =
>> heartRate)
>>
>> Error in lme(HR ~ drug * ordered(time), random = ~1 | person, correlation
>> = corAR1(,  :   formal argument "correlation" matched by multiple actual
>> arguments
>>
>>
>> Hopefully, you can help.
>>
>> Books on my shelve show R examples from behavioral science.  Need a
>> cookbook with R examples from  biology/agriculture, but have not found one.
>>
>>
>> Best regards,
>>
>> James F. Henson
>>
>> Research Scientist
>>
>> Southern University
>>
>> Baton Rouge, USA
>>
>> Wisdom is knowing what you don't know. ~ Socrates
>>
>>
>>
>>
>>
>> On Fri, Oct 16, 2015 at 6:24 AM, Thierry Onkelinx <
>> thierry.onkelinx at inbo.be> wrote:
>>
>>> Dear James,
>>>
>>> I think that you need to specify the order of the data as well.
>>> corAR1(form = ~time|person). Otherwise the order of the observations as
>>> present in the data is used.
>>>
>>> Best regards,
>>>
>>> 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
>>>
>>> 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
>>>
>>> 2015-10-14 18:46 GMT+02:00 James Henson <jfhenson1 at gmail.com>:
>>>
>>>> Greetings R Community
>>>>
>>>> Apologize for previously sending a csv file.
>>>>
>>>> My goal is to make orthogonal contrasts among simple effects in
>>>> analysis of
>>>> repeated measures data.  The SAS publication, on page 1224, shows how to
>>>> make this type of contrasts in SAS.  But, my search of books about
>>>> repeated
>>>> measures analysis using R, and on-line has not yielded a methodology.
>>>> Hopefully, someone can direct me to a book or publication that will
>>>> show me
>>>> a methodology.
>>>>
>>>> Statistical Analysis of Repeated Measures Data Using SAS Procedures
>>>>
>>>>
>>>> http://cslras.pbworks.com/f/littell_j_anim_sci_76_4_analysis_of_repeated_measures_using_sas.pdf
>>>>
>>>>
>>>>
>>>> Attached is a txt data file (file name = heart_rate.txt).  My code for
>>>> the
>>>> repeated measures analysis is below.
>>>>
>>>> library("nlme")
>>>>
>>>> # with AR1 variance/covariance structure, with ordered statement
>>>>
>>>> heartRate$time <- factor(heartRate$time)
>>>>
>>>> model2a <- lme(HR ~ drug*ordered(time), random =~1|person, correlation
>>>> =corAR1(, form=~1|person), data = heartRate)
>>>>
>>>> summary(model2a)
>>>>
>>>> anova(model2a)
>>>>
>>>> Making a new variable ‘simple’ that merges the variables drug and time
>>>> will
>>>> enable me to make orthogonal contrasts among the simple effects.  But,
>>>> when
>>>> using the variable ‘simple’ as the independent variable, the data will
>>>> no
>>>> longer be fitted to the AR1 variance/covariance structure.
>>>>
>>>> Thanks.
>>>>
>>>> Best regards,
>>>>
>>>> James F.Henson
>>>>
>>>> _______________________________________________
>>>> R-sig-mixed-models at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>>>
>>>>
>>>
>>
>

	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list