I am trying to fit a GAMLSS model with the response variable, y>0 with age and gender as independent variables. Since I need to model all 4 parameters of the distribution, I used BCPE as the family. The call is showing the error: Error in dBCPE(y, mu, sigma, nu, tau, log = TRUE) : mu must be positive
Please help
Since all values are positive, I am not able to identify the reason behind the error. Additionally, it is automatically running the code with GB2 family
The code is:
gamdata<-read.csv(file.choose(), header=T)
install.packages("gamlss")
library(gamlss)
age<-gamdata$age
gender<-gamdata$gender
A<-gamdata$A
m1<-gamlss(A~cs(age+gender, df=5),mu.formula=~cs(age+gender,df=5), sigma.formula=~cs(age+gender,df=5), nu.formula=~cs(age+gender,df=5), tau.formula=~cs(age+gender,df=5), family=gamlss.family(BCPE(mu.link="identity", sigma.link="log", nu.link="identity", tau.link="log")))
summary(m1)
The issued error is: Error in dBCPE(y, mu, sigma, nu, tau, log = TRUE) : mu must be positive
BCPE has a default identity link for mu. This can result in a negative mu value during the fitting iterations (especially if there are positive Y values very close to 0).
I recommend using BCPEo which has a default log link for mu. Consequently mu can never be negative.
If you have a lot of positive Y values very close to 0, and especially if the distribution of Y is reverse J shaped (i.e. density declining from Y=0) then you could try a GIG or GG distribution, or take log(Y) and find a suitable distribution for log(Y).
You could also try function chooseDist() to find a suitable distribution:
chooseDist( , type="realplus") for Y
chooseDist( , type="realline") for LY=log(Y)