1

I am new to coding as well as posting on forum but I will do my best to explain the problem and give enough background so that you're able to help me work through it. I have done a lot of searching for solutions to similar errors but all of the code that produces it and the format of the data behind it are very different.

I am working with biological data that consists of various growth categories but all that I am interested in is length (SCL in my code) and age (Age in my code). I have many lengths and age estimates for each individual through time and I am fitting a linear nlme model to the juvenile ages and a Von Bert curve to the mature ages. My juvenile model works just fine and I extracted h (slope of the line) and t (x intercept). I now need to use those parameters as well as T (known age at maturity) to fit the mature stage. The mature model will estimate K (this is my only unknown). I have included a subset of my data for one individual (ID50). This is information for only the mature years with the h and t from it's juvenile fit appended in the farthest right columns.

Subset of my data:

This didn't format very well but I'm not sure how else to display it

Grouped Data: SCL ~ Age | ID

ID  SCL Age     Sex Location MeanSCL Growth Year Status   T     h       t
50 86.8 27.75 Female   VA    86.8    0.2    1994 Mature 27.75 1.807394 -19.83368
50 86.9 28.75 Female   VA    87.1    0.4    1995 Mature 27.75 1.807394 -19.83368
50 87.3 29.75 Female   VA    87.5    0.5    1996 Mature 27.75 1.807394 -19.83368
50 87.8 30.75 Female   VA     88     0.4    1997 Mature 27.75 1.807394 -19.83368
50 88.1 31.75 Female   VA    88.1      0    1998 Mature 27.75 1.807394 -19.83368
50 88.1 32.75 Female   VA    88.2      0    1999 Mature 27.75 1.807394 -19.83368
50 88.2 33.75 Female   VA    88.3    0.2    2000 Mature 27.75 1.807394 -19.83368
50 88.4 34.75 Female   VA    88.4    0.1    2001 Mature 27.75 1.807394 -19.83368
50 88.4 35.75 Female   VA    88.4      0    2002 Mature 27.75 1.807394 -19.83368
50 88.5 36.75 Female   VA    88.5      0    2003 Mature 27.75 1.807394 -19.83368

This is the growth function:

vbBiphasic = function(Age,h,T,t,K) {
                 y=(h/(exp(K)-1))*(1-exp(K*((T+log(1-(exp(K)-1)*(T-t))/K)-Age)))
             }

This is the original growth model that SHOULD have fit:

ID50 refers to my subsetted dataset with only individual 50

VB_mat <- nlme(SCL~vbBiphasic(Age,h,T,t,K),
               data = ID50,
               fixed = list(K~1),
               random = K~1,
               start = list(fixed=c(K~.01))
          )

However this model produces the error:

Error in pars[, nm] : incorrect number of dimensions

Which tells me that it's trying to estimate a different number of parameters than I have (I think). Originally I was fitting it to all mature individuals (bur for the sake of simplification I'm now trying to fit to one). Here are all of my variations to the model code, ALL of them produced the same error:

  • inputting averaged values of (Age, h, T,t,K) of the whole population instead of the variables.
  • using a subset of 5 individuals and both (Age, h, T,t,K) as well as the averaged values for those individuals for each variable.
  • using 5 different individuals separately with both (Age, h, T,t,k) as well as their actual values for those variables (all ran individually i.e. 10 different strings of code just in case some worked and others didn't... but none did).
  • Telling the model to estimate all parameters, not just K
  • eliminating all parameters except K
  • Turning all values into vectors (that's what one forum with a similar error said to do)

Most of these were in an effort to change the number of parameters that R thought it needed to estimate, however none have worked for me.

Johan
  • 74,508
  • 24
  • 191
  • 319

1 Answers1

0

I'm no expert on nlme and often have similar problems when fitting models, especially when you cannot use nlsList to get started. My guess is that you have 4 parameters in your function (h, T, t, k), but you are only estimating one of them as both a fixed effect and with a random effect. I believe this then constrains the other parameters to zero which would in effect eliminate them from the model (but you still have them in the model!). Usually you include all the parameters as fixed, and then try to decide how many of them you also want to have a random effect. So I would include all 4 in the fixed argument and the start argument. Since you have 4 parameters, each one has to be either fixed or random, or both - otherwise, how can they be in the model?

rabil
  • 1
  • Sorry, looks like I misunderstood your function. I see now that h, T and t are observed values, not model parameters to be estimated.start = list(fixed=c(K~.01) – rabil Nov 11 '16 at 20:33
  • start = list(fixed=c(K~.01) – rabil Nov 11 '16 at 20:33
  • start = list(fixed=c(K~.01) – rabil Nov 11 '16 at 20:33
  • I am having trouble adding comments. start = list(fixed=c(K~.01) – rabil Nov 11 '16 at 20:33
  • Your start argument is incorrect: start = list(fixed=c(K~.01) – rabil Nov 11 '16 at 20:34
  • 1
    Should be: start = list(fixed=c(K=.01) . Every time I hit enter it adds a comment so I can't space out my answer. You need the = instead of the ~. You might also need to change "c(K=0.01)" to "list(K=0.01)". – rabil Nov 11 '16 at 20:37