0

I have decades of daily rainfall data, which are mostly zeroes (dry days). The Zero-Adjusted Gamma Distribution (ZAGA) fits the data relatively well. I'd like to plot the relationship between rainfall and a continuous variable, using ggplot2::geom_smooth(), with gamlss::gamlss(family=ZAGA()). However, when I try to do so, I get the following warning and the plot is empty:

Computation failed in `stat_smooth()`: arguments imply differing number of rows: 80, 81

The numbers of rows are 80, 81 for a largely number of different data (sub)sets that I've tried.

A MWE where this occurs:

library(gamlss)
library(dplyr)
library(ggplot2)

in_df <- tibble(x = c(0.1, 3.1, 3, 0.5, 2, 0.2, 2.9, 1.2, 1, 0.2),
                y = c(0, 2, 0, 0.2, 4, 0, 0, 1, 0, 0))

gamlss_fit <- gamlss(data = in_df, formula = y ~ x)    # works fine

ggplot(in_df) + 
    geom_smooth(aes(x = x, y = y), method = "gam", formula = y ~ x)  # "works" as well

ggplot(in_df) + 
    geom_smooth(aes(x = x, y = y), method = gamlss::gamlss, formula= y ~ x, se = F)  # gives warning 

Does this mean that gamlss is not supported with geom_smooth/stat_smooth? I found this forum post that suggests a workaround, but I was hoping to be able to use geom_smooth to also display a confidence interval on the plot and to do the fitting by grouping or faceting variable.

Alternatively, is there a distribution one could use with method = "gam" or another fitting function that would be appropriate for these data? I can't seem to find a zero-inflated continuous distribution (or mixed distribution) for this purpose.

climatestudent
  • 459
  • 4
  • 13
  • based on the rdocumentation of geom_smooth, you want to use an external function for your method so the code should be ```method = "gamlss::gamlss" ```. You need to tell the geom_smooth from which package the function for your method should come from. It doesn't check outside ggplot on it's on. ``` "gam" ``` is an argument within ggplot, ``` "gamlss" ``` is not. – Omniswitcher Jul 29 '22 at 15:10
  • Thank you @Omniswitcher, I've changed the call in the example above. The outcome is not changed. – climatestudent Jul 29 '22 at 15:31

0 Answers0