[R-sig-ME] nlme issue with multiple random effects and autoregression

sree datta @reedt@8 @end|ng |rom gm@||@com
Tue Nov 10 21:19:19 CET 2020


Hi Anne

I was able to fix your error. The error you are getting is due to how *date* is
being currently categorised as - *factor*. That is incorrect and the reason
why you are seeing NaNs. Instead if you convert it into a proper *date* using
the command below

*turtles$date <- as.Date(turtles$date) *   # I read in your csv file as a
dataframe called *turtles*

then I successfully execute the model command:

*library(nlme)*




*Mlme <- lme(odba_mean ~ T.range + species + T.range*species,
 random = ~ T.range|species/name_ID,             data = turtles,   # change
the name of data to your dataframe             correlation = corAR1(form =
~date|species/name_ID))*

Here is the output:

> *summary(Mlme)*
Linear mixed-effects model fit by REML
 Data: turtles
        AIC       BIC   logLik
  -8556.186 -8488.761 4290.093

Random effects:
 Formula: ~T.range | species
 Structure: General positive-definite, Log-Cholesky parametrization
            StdDev       Corr
(Intercept) 0.0023228641 (Intr)
T.range     0.0005050215 0

 Formula: ~T.range | name_ID %in% species
 Structure: General positive-definite, Log-Cholesky parametrization
            StdDev      Corr
(Intercept) 0.022010442 (Intr)
T.range     0.004108761 -0.484
Residual    0.027819874

Correlation Structure: ARMA(1,0)
 Formula: ~date | species/name_ID
 Parameter estimate(s):
Phi1
   0
Fixed effects: odba_mean ~ T.range + species + T.range * species
                                              Value           Std.Error
       DF           t-value      p-value
(Intercept)                            0.05806883 0.006167821     1986
 9.414805    0.0000
T.range                                0.00277333 0.001315326      1986
   2.108475    0.0351
species[T.Painted]               0.01371710 0.008022122      0
 1.709909     NaN
T.range:species[T.Painted] -0.00214764 0.001669308      1986
-1.286544    0.1984
 Correlation:
                           (Intr) T.rang s[T.P]
T.range                    -0.510
species[T.Painted]         -0.769  0.392
T.range:species[T.Painted]  0.402 -0.788 -0.493

Standardized Within-Group Residuals:
        Min          Q1                    Med              Q3
  Max
-3.20979441 -0.64327078 -0.06066791  0.57720480  5.88216284

Number of Observations: 2040
Number of Groups:
             species name_ID %in% species
                   2                   52




On Tue, Nov 10, 2020 at 2:56 PM sree datta <sreedta8 using gmail.com> wrote:

> Thanks Anne. Let me set up the models into a working condition and see if
> I can find a solution for you.
>
> Sree
>
> On Tue, Nov 10, 2020 at 8:58 AM Anne-Christine Auge <achr.auge using gmail.com>
> wrote:
>
>> Hello Sree,
>> thank you for your reply. I am attaching the datafile again here. Hope it
>> works this time.
>>
>> Species is set up as a factor. I am using R version 4.0.2.
>>
>> Here are is the output:
>>
>> > str(df3)
>> 'data.frame': 2040 obs. of  8 variables:
>>  $ name_ID  : Factor w/ 52 levels "Alison_2020",..: 1 1 1 1 1 1 1 1 1 1
>> ...
>>  $ name     : chr  "Alison" "Alison" "Alison" "Alison" ...
>>  $ year     : int  2020 2020 2020 2020 2020 2020 2020 2020 2020 2020 ...
>>  $ species  : Factor w/ 2 levels "Blandings","Painted": 2 2 2 2 2 2 2 2 2
>> 2 ...
>>  $ date     : Date, format: "2020-05-11" "2020-05-12" "2020-05-13"
>> "2020-05-14" ...
>>  $ Jday     : int  132 133 134 135 137 138 139 140 141 142 ...
>>  $ T.range  : num  3.63 4.51 3.39 4.95 5.36 ...
>>  $ odba_mean: num  0.0613 0.0169 0.0306 0.0225 0.0254 ...
>>
>> > head(df3, n=10)
>>        name_ID   name year species       date Jday  T.range  odba_mean
>> 1  Alison_2020 Alison 2020 Painted 2020-05-11  132 3.630952 0.06125982
>> 2  Alison_2020 Alison 2020 Painted 2020-05-12  133 4.507440 0.01687152
>> 3  Alison_2020 Alison 2020 Painted 2020-05-13  134 3.392361 0.03059397
>> 4  Alison_2020 Alison 2020 Painted 2020-05-14  135 4.951389 0.02250526
>> 5  Alison_2020 Alison 2020 Painted 2020-05-16  137 5.362847 0.02542538
>> 6  Alison_2020 Alison 2020 Painted 2020-05-17  138 6.307292 0.04627075
>> 7  Alison_2020 Alison 2020 Painted 2020-05-18  139 6.208333 0.03905372
>> 8  Alison_2020 Alison 2020 Painted 2020-05-19  140 4.828125 0.04999669
>> 9  Alison_2020 Alison 2020 Painted 2020-05-20  141 7.390625 0.04744481
>> 10 Alison_2020 Alison 2020 Painted 2020-05-21  142 6.901042 0.05230780
>>
>> > class(df3$species)
>> [1] "factor"
>>
>>
>> On Mon, 9 Nov 2020 at 22:45, sree datta <sreedta8 using gmail.com> wrote:
>>
>>> I do not see the data file. Please attach it if possible. In addition,
>>> how is the "species" variable set-up? Is it coded as a numeric variable or
>>> as a factor? Since you only have two species, if species is not set up as a
>>> factor variable and data within species is in a string/character format,
>>> that can generate NaNs.
>>> What version of R are you using? Starting with R V4.0,
>>> StringsAsFactors=FALSE is the default setting.
>>>
>>> Please send the results of the following commands:
>>>
>>> str(data) (where data is the name of your data-frame)
>>>
>>> head(data, n = 10)
>>>
>>> class(data$species)
>>>
>>> Sree
>>>
>>> On Mon, Nov 9, 2020 at 5:55 PM Anne-Christine Auge <achr.auge using gmail.com>
>>> wrote:
>>>
>>>> I am trying to analyse the effect of temperature range (T.range) on
>>>> turtle
>>>> animal activity (odba_mean).
>>>> I have multiple daily measurements for multiple individuals (name_ID)
>>>> from
>>>> two species. I have data for 3 years (no turtle repeats over the
>>>> years). A
>>>> datafile is attached.
>>>> Activity (mean_ODBA) measures appear to be temporally autocorrelated, so
>>>> this needs to be accounted for).
>>>>
>>>> I am fairly new to mixed models, so I am very unsure about my code. I am
>>>> using the nlme package because this seems to one that can more easily
>>>> account for autoregression.
>>>> This is the code I have so far:
>>>>
>>>> Mlme <- lme(odba_mean ~ T.range + species + T.range*species,
>>>>              random = ~ T.range|species/name_ID,
>>>>              data = df3,
>>>>              correlation = corAR1(form = ~date|species/name_ID))
>>>>
>>>>
>>>> I have a couple issues that I cannot seem to solve:
>>>> 1. I get the warning: "Warning message: In pt(-abs(tVal), fDF) : NaNs
>>>> produced" which appears to be due to the nesting structure, but I just
>>>> do
>>>> not know how to fix it.
>>>> 2. I cannot figure out how to include year as another random effect. I
>>>> read
>>>> that it is very difficult in nlme to include multiple random effects
>>>> that
>>>> are not nested. I suppose technically name_ID is nested in years, but
>>>> it is
>>>> already nested in species, and species is not nested in years (but
>>>> crossed). How do I incorporate this?
>>>>
>>>> Thank you.
>>>> Regards,
>>>> Anni
>>>>
>>>> --
>>>> *_________________________________________*
>>>>
>>>>
>>>> *Anne-Christine Auge*
>>>> _______________________________________________
>>>> R-sig-mixed-models using r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>>>
>>>
>>
>> --
>> *_________________________________________*
>>
>>
>> *Anne-Christine Auge*
>>
>

	[[alternative HTML version deleted]]



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