Problems adjusting a mixed effects model using the gamlss package

Asked

Viewed 35 times

0

I’m trying to adjust a mixed effects model considering the package gamlss.

The data is here: https://drive.google.com/file/d/1q4XuSPnZXx7TsrT3JVoucFyxeOSegWFz/view?usp=sharing

The model I’m adjusting is defined below:

library(gamlss)
ModelGamlss <- gamlss(log(Var1)~re(fixed=~log(Var2)+log(Var3)+
(Var4)+(Var5),random = list(Var6=pdDiag(~Var7))),
data=Data2)

However, the following error is shown:

Error in gamlss(log(Var1) ~ re(fixed = ~log(Var1)~re(fixed=~log(Var2)+log(Var3)+(Var4)+ : 
  The data contains NA's, use data = na.omit(mydata)

After encountering this error, I made the following change in the syntax of the considered model:

ModelGamlss <- gamlss(log(Var1)~re(fixed=~log(Var2)+log(Var3)+
(Var4)+(Var5),random = list(Var6=pdDiag(~Var7))),
data=na.omit(Data2))

However, a new error is presented:

Error in lm.wfit(x, z, w, method = "qr", ...) : 0 (non-NA) cases

How could it solve the problems previously faced? Since the first error informs that there are Na’s in the database, however, when looking at the database no NA is observed, and more, what would be the reason this second error message is appearing when trying to adjust the above model?

1 answer

1


The problem must be how the data is read from Google Drive. The link file is a CSV file with commas as marker for decimals. And the column separator is the semicolon, ";". To read files in this CSV format read.csv2.

library(gamlss)

ModelGamlss <- gamlss(
  log(Var1) ~ re(fixed = ~ log(Var2) + log(Var3) + Var4 + Var5,
                 random = list(Var6 = pdDiag(~ Var7))),
  data = Data2)
#GAMLSS-RS iteration 1: Global Deviance = -1706.294 
#GAMLSS-RS iteration 2: Global Deviance = -1706.294 

summary(ModelGamlss)
#******************************************************************
#Family:  c("NO", "Normal") 
#
#Call:  gamlss(formula = log(Var1) ~ re(fixed = ~log(Var2) +  
#    log(Var3) + Var4 + Var5, random = list(Var6 = pdDiag(~Var7))),  
#    data = Data2) 
#
#Fitting method: RS() 
#
#------------------------------------------------------------------
#Mu link function:  identity
#Mu Coefficients:
#            Estimate Std. Error t value Pr(>|t|)    
#(Intercept) 3.100661   0.002601    1192   <2e-16 ***
#---
#Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
#------------------------------------------------------------------
#Sigma link function:  log
#Sigma Coefficients:
#            Estimate Std. Error t value Pr(>|t|)    
#(Intercept) -2.70187    0.02742  -98.53   <2e-16 ***
#---
#Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
#------------------------------------------------------------------
#NOTE: Additive smoothing terms exist in the formulas: 
# i) Std. Error for smoothers are for the linear effect only. 
#ii) Std. Error for the linear terms maybe are not accurate. 
#------------------------------------------------------------------
#No. of observations in the fit:  665 
#Degrees of Freedom for the fit:  49.27846
#      Residual Deg. of Freedom:  615.7215 
#                      at cycle:  2 
# 
#Global Deviance:     -1706.294 
#            AIC:     -1607.737 
#            SBC:     -1385.995 
#******************************************************************

Data reading

Of help("read.csv2"), my emphasis:

read.csv and read.csv2 are identical to read.table except for the defaults. They are intended for Reading ?comma separated value' files (?.csv') or (read.csv2) the Variant used in countries that use a comma as decimal point and a semicolon as field separator.

Translation Google, edited:

read.csv and read.csv2 are identical to read.table except for standards. They are intended to read from comma-separated values of the files of the files of the files of the files of the files of the files of the files of the files' (i.e.:csv') or (read.csv2) the variant used in countries that use a comma as a decimal point and a semicolon as a field separator.

google_id <- "1q4XuSPnZXx7TsrT3JVoucFyxeOSegWFz"
google_file <- sprintf("https://docs.google.com/uc?id=%s&export=download", google_id)
Data2 <- read.csv2(google_file)
  • Hello Rui! Thank you so much for your feedback. So, strange that even I using the following command Data2 <- read.csv2("DataNew.csv", header=T, sep=";", dec=",") the error still continues.

  • Rui, that part of your code "https://docs.google.com/uc?id=%s&export=download" you picked up where?

  • 1

    @Brenog. I don’t know where I found it, but I’ve used it ever since and it’s (almost?) always right. O id=%s will take the value id=1q4XuSPnZXx7TsrT3JVoucFyxeOSegWFz, see ?sprintf.

  • 1

    @Brenog. You can also download and then Data2 <- read.csv2("DataNew.csv") enough, the other arguments are not necessary, because those are already the values that have. The read.csv2 is a deliberately inflexible form of read.table with the appropriate arguments.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.