[R-sig-ME] nlme::gnls Warning Message Suggests Potential Bug

biii m@iii@g oii de@@ey@ws biii m@iii@g oii de@@ey@ws
Sat Sep 18 21:09:44 CEST 2021


Hello,

 

While working on an nlme::gnls model just now, I made an error in the model
specification where I included a params argument without specifying all of
the params.  When I did that, I got a warning that suggested that the error
in the params argument should have been caught earlier.

 

Is this something that should be fixed?  (Not exactly a bug but some level
of issue seems to be afoot.)

 

Thanks,


Bill

 

``` r

library(nlme)

#> Warning: package 'nlme' was built under R version 4.1.1

set.seed(5)

d <-

  expand.grid(

    STUDYID=c("A", "B"),

    ANIMAL=factor(1:10)

  )

d$indep <- 1:nrow(d)

d$value <- exp(rnorm(nrow(d)))

 

model <- gnls(value~e0+slope*indep, data=d, start=c(e0=0, slope=0))

model <-

  gnls(

    value~e0+slope*indep,

    data=d,

    # Whoops, I forgot to include 'slope' in the 'params'

    params=e0~STUDYID,

    start=c(e0=c(0, 0), slope=0),

    weights=varExp(form=~fitted(.))

  )

#> Warning in terms.formula(formula, data = data): 'varlist' has changed
(from

#> nvar=4) to new 5 after EncodeVars() -- should no longer happen!

#> Error in eval(predvars, data, env): object 'slope' not found

# But, the warning suggests that something should have been caught sooner.

 

# When I include 'slope' in the 'params' argument, everything is fine.

model <-

  gnls(

    value~e0+slope*indep,

    data=d,

    params=

      list(

        e0~STUDYID,

        slope~1

      ),

    start=c(e0=c(0, 0), slope=0),

    weights=varExp(form=~fitted(.))

  )

```

 

<sup>Created on 2021-09-18 by the [reprex
package](https://reprex.tidyverse.org) (v2.0.1)</sup>


	[[alternative HTML version deleted]]



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