GAMLSS错误:响应变量超出范围

时间:2018-08-21 23:28:36

标签: gam

我无法理解为什么收到此错误。我的两个变量都是数字变量,并且长度相同,当变量不相同时,我用NA调整数据。但是我仍然收到错误消息,我的响应变量超出范围

    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)

gamlss中的错误(公式= table $ BF〜x1 + x2,family = GA):   响应变量超出范围 另外:有50个或更多警告(请使用warnings()查看前50个警告)

1 个答案:

答案 0 :(得分:0)

问题出在y变量的0值中。如果响应变量中为0,则无法使GAMLSS符合Gamma分布。

注意:您示例中的代码不可重现,因此我无法理解在处理数据后,y变量是否仍以0结尾。