[R-sig-ME] Within group estimate of autocorrelation

PATRICK, Samantha spatrick at glos.ac.uk
Mon Sep 22 20:39:12 CEST 2014


Hi

I have a model which fits an corAR1 autocorrelation structure and the code tells the model that time is nested within individual:

fit0<-lme(Respone~1,
random=~1|indiv,
correlation=corAR1(form=~time|indiv),
data=Data2, method = "REML")

>From this I get a Phi single estimate of the autocorrelation.  However  I want to have an estimate of the autocorrelation for each individual.  I have checked but can not find any code to extract this value.

So my first question is: Is it possible to extract an estimate of autocorrelation per individual or does the model not save/calculate this?
And second, if it isn't possible, I wondered if there is any way to use the weights function to group individuals.

If I add the code:  weights=varIdent(form=~1|group), I can fit multiple residual variance terms so I wondered if this could be used to estimate a Phi value per group, by somehow structuring the model so it fits an autocorrelation for each residual variance group?

The solution does not need to be lme necessarily - I’m open to any suggestions!

Many Thanks

Sam


Dr Samantha Patrick
Research Fellow
Biosciences QU116
Francis Close Hall Campus
University of Gloucestershire
Cheltenham, GL50 4AZ, UK

Research Associate: OxNav, University of Oxford

******From 1st August - 14th November 2014 I will be
based in Montréal, which is 5 hours behind GMT  ******

Tel: 07740 472 719
Skype: sammy_patrick
https://sites.google.com/site/samanthacpatrick/

From: Alex Whitworth<mailto:whitworth.alex at gmail.com>
Sent: ‎Thursday‎, ‎18‎ ‎September‎ ‎2014 ‎11‎:‎21
To: Ben Bolker<mailto:bbolker at gmail.com>
Cc: r-sig-mixed-models at r-project.org<mailto:r-sig-mixed-models at r-project.org>

I've tried installing from github on my personal computer as well (in case
there was something with my work network causing a problem). I ran into the
same error. I am able to install other github packages--for example, my
(admittedly very small) package on nongaussian mixture
modeling: devtools::install_github("emclustr","crossfitAL").

I'll re-attempt the binary today--currently having some problems
downloading it.

Regarding question #2 (my hacked function), I completely agree that a
proliferation of predict.merMod functions is undesirable. the random
component of my model is as follows

lmer(... (0 + <logical> + <factor> |subject/school), data= ...)

The issue is selecting the appropriate columns of the random effects
data-frame { ranef(object)[[1]] } when the intercept term is
suppressed--but allowing flexibility in the function when the intercept is
not suppressed. It's made more difficult by the factor variable having 3-4
levels.

Alex



Alex Whitworth
whitworth.alex at gmail.com
(c) 828.429.7478

On Wed, Sep 17, 2014 at 1:37 PM, Ben Bolker <bbolker at gmail.com> wrote:

>
>
> On Wed, Sep 17, 2014 at 3:22 PM, Alex Whitworth <whitworth.alex at gmail.com>
> wrote:
>
>> Dr Bolker,
>>
>> I tried installing the development / github version of lme4 today and ran
>> into an error. R system messages copied below. Any help would be
>> appreciated.
>>
>
>   I'm cc'ing this to r-sig-mixed-models in case anyone has an idea.
>   In the meantime,
> * I'm also posting a Windows binary of the latest development version
> (today's github version), as built by CRAN's win-builder, to
> http://lme4.r-forge.r-project.org/repos/ ; it will take up to 24 hours to
> show up there
> * I've also put a version at
> http://ms.mcmaster.ca/~bolker/R/bin/windows/contrib/3.1/ , available
> immediately
>
>   You can install this under R 3.1.* with an appropriate
> install.packages(...,repos=...) incantation, or download the .zip file and
> install it locally.
>
>
>>
>> On a second note, I'm still working on my "hacked" version of the predict
>> function predict.merMod2() . I've solved one of the issues I was running
>> into but am still working on an issue related to the random effects for
>> grouping variables that are of type factor.
>>
>
>   (What other kinds of grouping variables are there ...  ?)
>
>
>
>> I hope to be able to solve this / put the solution on stackoverflow in
>> the near-ish future.
>>
>
>   I'm hoping that the predict.merMod in the development version will solve
> all your problems, or that if it doesn't you can create a small
> reproducible example and I can fix it centrally.  Provide that you're not
> trying to do something really weird/baroque, it makes more sense to have
> the package Just Work than to have a proliferation of individual
> fixes/workarounds.
>
>
>>
>>
>>
>> -------------------------------------------------------------------------------------------------------------------
>> Restarting R session...
>>
>> > devtools::install_github("lme4","lme4")
>> Installing github repo lme4/master from lme4
>> Downloading master.zip from
>> https://github.com/lme4/lme4/archive/master.zip
>> Installing package from
>> C:\Users\alewit\AppData\Local\Temp\RtmpYHOfgM/master.zip
>> Installing lme4
>> "C:/PROGRA~1/R/R-31~1.1/bin/x64/R" --vanilla CMD build  \
>>
>> "C:\Users\alewit\AppData\Local\Temp\RtmpYHOfgM\devtools138845a711f6\lme4-master"
>> --no-manual  \
>>   --no-resave-data
>>
>> * checking for file
>> 'C:\Users\alewit\AppData\Local\Temp\RtmpYHOfgM\devtools138845a711f6\lme4-master/DESCRIPTION'
>> ... OK
>> * preparing 'lme4':
>> * checking DESCRIPTION meta-information ... OK
>> * cleaning src
>> Warning in cleanup_pkg(pkgdir, Log) :
>>   unable to run 'make clean' in 'src'
>> * installing the package to build vignettes
>> Warning: running command '"C:/PROGRA~1/R/R-31~1.1/bin/x64/Rcmd.exe"
>> INSTALL -l "C:\Users\alewit\AppData\Local\Temp\Rtmp2ppmfo\Rinst13c46423bb3"
>> --no-multiarch
>> "C:/Users/alewit/AppData/Local/Temp/Rtmp2ppmfo/Rbuild13c45c0e2b4e/lme4"'
>> had status 1
>>       -----------------------------------
>> * installing *source* package 'lme4' ...
>> ** libs
>> Warning: running command 'make -f "Makevars.win" -f
>> "C:/PROGRA~1/R/R-31~1.1/etc/x64/Makeconf" -f
>> "C:/PROGRA~1/R/R-31~1.1/share/make/winshlib.mk"
>> SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)'
>> SHLIB="lme4.dll" WIN=64 TCLBIN=64 OBJECTS="external.o glmFamily.o
>> mcmcsamp.o optimizer.o predModule.o respModule.o"' had status 127
>> ERROR: compilation failed for package 'lme4'
>> * removing
>> 'C:/Users/alewit/AppData/Local/Temp/Rtmp2ppmfo/Rinst13c46423bb3/lme4'
>>       -----------------------------------
>> ERROR: package installation failed
>> Error: Command failed (1)
>>
>
>   I'm not  sure what's going on here.  Googling for "status 127" suggests
> that it's a pretty generic error code, so it doesn't give a lot of clues.
> Is it possible you're having permissions errors (hinted at by "unable to
> run 'make clean' in 'src'"?  What happens if you try disabling vignette
> building using build_vignettes=FALSE in your install_github() ?
>
>   Are you able to install other packages from github?
>
>
>> Alex Whitworth
>> whitworth.alex at gmail.com
>> (c) 828.429.7478
>>
>> On Thu, Aug 28, 2014 at 4:13 PM, Ben Bolker <bbolker at gmail.com> wrote:
>>
>>> On 14-08-28 06:46 PM, Alex Whitworth wrote:
>>> > Dr. Bolker,
>>> >
>>> > Could you please take a look at the function I have posted on
>>> > StackOverflow
>>> > <
>>> http://stackoverflow.com/questions/25538199/design-matrix-for-mlm-from-librarylme4-with-fixed-and-random-effects
>>> >?
>>> > I believe that it is working correctly and would appreciate your
>>> review.
>>> >
>>> > Thanks,
>>> >
>>> > Alex Whitworth
>>> > whitworth.alex at gmail.com <mailto:whitworth.alex at gmail.com>
>>> >
>>>
>>>   I saw that.  I will look at it if I have a chance.  I am
>>> simultaneously impressed by your incentive and ability to solve your own
>>> problems and a little bit frustrated at our inability to communicate
>>> very effectively: I think your problems could probably be fixed by a
>>> fairly minor adjustment to predict.merMod , which is likely better
>>> tested and handles a wider range of cases.  On the other hand, if you
>>> needed the solution right away ...  ( a workaround that occurred to me
>>> would be to make predictions on an augmented set of new data that
>>> included all of the factor levels, then throw away the ones you don't
>>> want).
>>>
>>>   If you want to test your function thoroughly, you can try the tests
>>> outlined in
>>>
>>> https://github.com/lme4/lme4/blob/master/tests/predsim.R
>>> https://github.com/lme4/lme4/blob/master/inst/tests/test-methods.R
>>> (search in this one for context("predict"))
>>>
>>>  By the way, getting standard errors of predictions that account
>>> properly for uncertainty in the random-effects parameters is (alas) a
>>> considerably harder problem ...
>>>
>>>   cheers
>>>     Ben Bolker
>>>
>>>
>>
>

 [[alternative HTML version deleted]]

_______________________________________________
R-sig-mixed-models at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
-
‘In the top 5 in the Green League Table; committed to sustainability’
This email is confidential to the intended recipient. If you have received it in error please notify the sender and delete it from your computer.
The University of Gloucestershire is a company limited by guarantee registered in England and Wales.  Registered number: 06023243.  Registered office: The Park, Cheltenham, GL50 2RH
Please consider the environment before printing this email.
-



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