Jessica Ayers
Jessica Ayers

Reputation: 61

GAMLSS Error: Response Variable out of range

I cannot fathom why I am receiving this error. Both my variables are numeric and of the same length, and I adjust the data with NAs when they are not; however I am still receiving an error that my response variable is out of range

    year <- c(1,2,3,4,5,6,7,8,9,10)
    y <- c(19.36, 0, 0, 0.06, 0,0, 1.58, 2.37, 0,0)
    x1 <- c(99.735835998,32.73874517,10.8545887,47.96341768,6.29940882,22.55498627,16.64656661,4.234896268,0.571722269,53.45872813)

    months = c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

    Drivers = c("P","T")
    ModelName = paste0(Drivers[1],"_",Drivers[2])
    ModelNumb = 2

for (s in 1:length(months))
{

  station_summary = data.frame(matrix(NA,length(stations),3))
  colnames(station_summary)=c("Station", "ModelName", "ModSelection")
  month = months[s]

  for (se in 1:length(stations))
  {

    station = stations[se]
    table = read.csv(paste0("D:/BF_Factors/Regroup Drivers/All_Drivers_BF_P_T/",station,"/Table_",station,"_",month,".csv"),sep=",",header = T)
    table = subset(table, select=c("Year","BF",Drivers))
    table = table[1:50,]

    # Clean the data according to the model used. Some years have been excluded because no data where available

    table[is.na(table[,2]),3] = NA
    table[is.na(table[,2]),4] = NA
    table[is.na(table[,3]),2] = NA
    table[is.na(table[,3]),4] = NA
    table[is.na(table[,4]),2] = NA
    table[is.na(table[,4]),3] = NA

    if (length(which(table[,2]>0))>=5) # If at least 5 values are higher than 0
    {

      x1 = table$P #first Driver
      x2 = table$T

     mod.GA1 <- gamlss(y~x1,sigma.fo=~1,family=GA) 
     mod.GA2 <- gamlss(y~x1+x2,sigma.fo=~1,family=GA)

Error in gamlss(formula = table$BF ~ x1 + x2, family = GA) : response variable out of range In addition: There were 50 or more warnings (use warnings() to see the first 50)

Upvotes: 5

Views: 2159

Answers (1)

Simone Bianchi
Simone Bianchi

Reputation: 143

The problem is in the 0 values in your y variable. You cannot fit a GAMLSS with Gamma distribution if you have 0 in the response variable.

Caveat: the code in your example is not reproducible so I cannot understand if after processing the data you still end up with 0s in the y variable.

Upvotes: 2

Related Questions