[R] HELP ERROR WHEN USING GAMMA2 IN VGLM TO SET MU AS AN INTERCEPT
Khedhaouiria Dikra
Dikra.Khedhaouiria at ete.inrs.ca
Wed Sep 16 23:50:31 CEST 2015
Hi everyone,
I'm trying to fit several models with the VGAM packages using the gamma2 function with an identity function link.
I have two vectors, x_m and y_m and I try to work on the model y_m~x_m.
My code is below, but I want to explain my problem first:
First, I took the default model proposed in vgml function (fit1 below), i.e. shape as an intercept --> no problem
Then, I tried the model with zero=NULL (fit3 below), meaning that all parameters are modelled as a function of the explanatory variables (x_m) --> again no problem
Finally, I tried to model mu parameter as an intercept only , i.e. setting zero=1, here my problems begin. In fact, I have the following error message:
VGLM linear loop 1 : loglikelihood = NaN
Error in if (take.half.step) { : missing value where TRUE/FALSE needed
In addition: Warning message:
In dgamma(x = y, shape = c(shapemat), scale = c(mymu/shapemat), :
production de NaN
I tried to change the initial value (inject estimated parameters of fit2 in fit3) , the number of iteration, but nothing changed, always the same problem.
I tried other link functions (log), it worked but I really want to make it works with the identity link.
Thank you so much!
Dikra
Here is my code:
# Empty the environnement
rm (list=ls())
#--- needed environnment
library(VGAM)
#------------ set the working directorty
pathWork <- "C:/mydata/"
setwd(pathWork)
#--------- load my data
dataXmodel <- read.table("x_m.txt")
dataYmodel <- read.table("y_m.txt")
# ------ set the data frame
xmodel <- dataXmodel$x
ymodel <- dataYmodel$x
gdata = data.frame(xmodel , ymodel)
#------------ fit 1
fit1 <- vglm(ymodel ~ xmodel, family = gamma2(lmu ="identitylink", lshape="identitylink"),
trace = TRUE , data = gdata, na.action = "na.omit")
# identify potential initial values for next steps
CoefFit1 <- coef(fit1)
valinitial2 = c(CoefFit1, 0.01)
valinitial3 = c(CoefFit1[1], CoefFit1[2], 0.02)
# --------- fit 2
fit2 <- vglm(ymodel ~ xmodel, family = gamma2(lmu ="identitylink", lshape="identitylink", zero = NULL),
trace = TRUE , data = gdata, na.action = "na.omit", coefstart =valinitial2 )
# --------- fit 3
fit3 <- vglm(ymodel ~ xmodel, family = gamma2(lmu ="identitylink", lshape="identitylink", zero = 1),
trace = TRUE , data = gdata, na.action = "na.omit" , coefstart = valinitial3 , maxit=60)
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: x_m.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150916/a073ab3d/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: y_m.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150916/a073ab3d/attachment-0001.txt>
More information about the R-help
mailing list