[R] nlme, predict.nlme, levels not allowed
Patrick Giraudoux
patrick.giraudoux at univ-fcomte.fr
Sun Nov 6 09:03:38 CET 2005
Going through the R-Dev list, I have found this (from Pedro Afalo),
dated 8 April 2004:
> Dear Richard,
>
> The problem that you report is documented (but no solution given) in the
> file ch08.R in the scripts directory of nlme package.
>
> I have found the following workaround just by chance, but it may
> give a clue of what is the problem to those who know how to program
> in R.
>
> The solution is to add an explicit call to factor in the nlme call.
> In the case of the error reported by Richard the following call to nlme
> in the ch08.R file can be used:
>
> fm4CO2.nlme <- update( fm3CO2.nlme,
> fixed = list(Asym + lrc ~ factor(Type) * factor(Treatment), c0 ~ 1),
> start = c(fm3CO2.fix[1:5], 0, 0, 0, fm3CO2.fix[6]) )
>
> instead of:
>
> fm4CO2.nlme <- update( fm3CO2.nlme,
> fixed = list(Asym + lrc ~ Type * Treatment, c0 ~ 1),
> start = c(fm3CO2.fix[1:5], 0, 0, 0, fm3CO2.fix[6]) )
>
> I hope this helps,
>
> Pedro.
I have tried the workaround for my own case and it works...
Any news since then about fixing the problem?
Patrick
Patrick Giraudoux a écrit :
> Dear listers,
>
> I am trying to fit a nlme model with "age" and "pds" as reals, and
> "zone" a factor with two levels "Annaba" and "Boumalek" . The "best"
> model found is the following:
>
> > modm3
> Nonlinear mixed-effects model fit by maximum likelihood
> Model: pds ~ Asym/(1 + exp((xmid - age)/scal))
> Data: croispulm
> Log-likelihood: -91.86667
> Fixed: list(Asym ~ zone, xmid ~ zone, scal ~ 1)
> Asym.(Intercept) Asym.zoneBoumalek xmid.(Intercept)
> xmid.zoneBoumalek scal
> 9.99551079 0.39423966 4.97981027
> 0.06969807 2.23116661
>
> Random effects:
> Formula: list(Asym ~ 1, xmid ~ 1)
> Level: nichoir
> Structure: General positive-definite, Log-Cholesky parametrization
> StdDev Corr Asym.(Intercept) 1.796565e-06 As.(I)
> xmid.(Intercept) 1.219400e-04 0 Residual 6.163282e-01
> Correlation Structure: Continuous AR(1)
> Formula: ~age | nichoir
> Parameter estimate(s):
> Phi
> 0.3395242
> Number of Observations: 102
> Number of Groups: 17
>
>
> Everything normal so far.
>
> Things come to be strange when I try to compute predicted values:
>
> > pred<-predict(modm3,newdata=mydata,type="response")
> Error in predict.nlme(modm3, newdata = mydata, type = "response") :
> Levels Annaba,Boumalek not allowed for zone
>
> I have checked and re-checked that zone in the newdata is well a
> factor with the "good" levels, and I can hardly understand why these
> two levels used when fitting the model are now rejected when used for
> computing predicted values.
>
> Any hint welcome,
>
> Best regards,
>
> Patrick
>
>
>
>
More information about the R-help
mailing list