[R-sig-ME] Data Handling within nlme library

biii m@iii@g oii de@@ey@ws biii m@iii@g oii de@@ey@ws
Mon Aug 2 03:43:19 CEST 2021


Hello,

 

I'm having an issue with data handling within the nlme library.
Specifically, when I fit a gnls model within one function, I cannot update
that model within another function with new data.  Are there any ways to
give data within a function and have the model work outside?  An example of
what I'm trying to do is below in the first example:

 

``` r

library(nlme)

 

make_model <- function() {

  my_soybean <- Soybean

  gnls(weight ~ SSlogis(Time, Asym, xmid, scal), data=my_soybean, weights =
varPower())

}

 

my_model <- make_model()

#> Error in stats::nls(formula = weight ~ SSlogis(Time, Asym, xmid, scal), :
object 'my_soybean' not found

# Issue: my_soybean is in the function environment but not found during
estimation

 

make_model <- function() {

  time <- Soybean$Time

  weight <- Soybean$weight

  gnls(

    weight ~ Asym/(1+exp((xmid-time)/scal)),

    start=c(Asym=30, xmid=40, scal=10),

    weights = varPower()

  )

}

 

my_model <- make_model()

#> Error in terms.formula(formula, data = data): '.' in formula and no
'data' argument

# Issue: No idea where the error is coming from (making a guess that it is
the weights argument)

 

make_model <- function() {

  time <- Soybean$Time

  weight <- Soybean$weight

  gnls(

    weight ~ Asym/(1+exp((xmid-time)/scal)),

    start=c(Asym=30, xmid=40, scal=10),

  )

}

 

my_model <- make_model()

# Issue: when data are given in the local environment but not with a `data`

# argument, it works.

```

 

<sup>Created on 2021-08-01 by the [reprex
package](https://reprex.tidyverse.org) (v2.0.0)</sup>

 

Thanks,

 

Bill

 

P.S.  I'm pretty sure that this is also related to an issue found in the
nlraa library described at https://github.com/femiguez/nlraa/issues/4


	[[alternative HTML version deleted]]



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