0

I have repeated measures data examining forest Biomass across forest Age for multiple Plots:

In other words: Biomass ~ Age | Plot

#Reproducible Example data:

biom.dat <- c(unlist(lapply(1:7, function(x){ set.seed(x) ; sort(sample(2:500,15))})),
  unlist(lapply(8:15, function(x){ set.seed(x) ;  c(sort(sample(2:500,12)),(sample(90:500,3)))})))
dat <- data.frame(Plot = rep(1:5,each = 15), Age = rep(c((1:75)[(1:5)%%5 == 0])+8,5), Biomass = biom.dat)

> head(dat)
  Plot Age Biomass
1    1  13      32
2    1  18      88
3    1  23     101
4    1  28     102
5    1  33     134
6    1  38     187

I tried using nlmer to examine a non-linear trend in this data. I use nlmer so I incorporate the Plot structure as a random effect.

I'm trying to run an extension of the model seen here that uses this custom function:

enter image description here

which I've coded in R as:

function(Age,C,Ao,s,wd,ph) C + Ao * exp(-s*Age) * cos(wd*Age + ph)

However, when I run the nlmer code (see below), I get the following error:

Error in initializePtr() : Downdated VtV is not positive definite

This discussion suggested to me that I might have a scaling problem? (which was hinted at here).

So I tried scaling the variables (1st just the Age predictor, but then also the Biomass response). Even after scaling both variables, I still get the same error...

Questions:

  1. What else could be going wrong? (What else should I check?)

  2. Where do I go from here?


My Code:

Update: Based on deleted @42 comments, I've adjusted the code (originally inspired by here) to more closely match code from the nlmer help page (Example #3): [Note: the errors still occur]

  #Create equation:
    LTI.eqn <- ~ C + Ao * exp(-s*Age) * cos(wd * Age + ph)

  #Build function (incorporating a "gradient" attribute in the formula using deriv():
    LTI.func <- deriv(LTI.eqn, namevec = c('C', 'Ao', 's', 'wd', 'ph'),
                  function.arg = c('Age', 'C', 'Ao', 's', 'wd', 'ph'))

  #Load package:  
    library(lme4)

  #Create named vector of starting values for my constants:
    nlmer.start <- c(C = 0,Ao = -1,s = 1,wd = 1,ph = 0)

  #Run model:
    nlmer(Biomass ~ LTI.func(Age, C, Ao, s, wd, ph) ~ (Age | Plot), 
          data = dat, start=nlmer.start)

     #Error in initializePtr() : Downdated VtV is not positive definite

  #So let's rescale the continuous predictor variables (in this case we'll center Age):
    nlmer(Biomass ~ LTI.func(Age, C, Ao, s, wd, ph) ~ (Age | Plot), 
          data = transform(dat,Age = Age - 51), start = nlmer.start)

     #Error in initializePtr() : Downdated VtV is not positive definite

  #Still a problem. What if I scale Biomass, too???
    datt <- transform(dat,Age = (Age - 51), Biomass = scale(Biomass, center = F))
    nlmer(Biomass ~ LTI.func(Age, C, Ao, s, wd, ph) ~ (Age | Plot),
          data = datt, start = nlmer.start)

     #Error in initializePtr() : Downdated VtV is not positive definite
theforestecologist
  • 4,667
  • 5
  • 54
  • 91
  • I chose `nlmer` vs `nlme` because I have numerous other models already generated using `lme4` to compare to (of course, using REML = F) – theforestecologist May 05 '18 at 18:00
  • I'm not sure I should be commenting further and don't really have the experience to certify an answer but perhaps following BenBolker's advice here: http://rpubs.com/bbolker/3423 . I'll delete my earlier comments to make room for other contributions. – IRTFM May 05 '18 at 18:57
  • @42 thanks for your time and comments! Just FYI, I've adjusted the function and still get the same errors. I'll check out your Bolker link to see if it'll help. Thanks! – theforestecologist May 05 '18 at 19:15
  • @42 I tried Ben's `tmpstr <- deparse(` approach from the [link you shared](http://rpubs.com/bbolker/3423). Unfortunately, although it definitely changed the function call, it did nothing to alleviate the cause of the error. Thanks though! – theforestecologist May 05 '18 at 21:21

0 Answers0