gamlss-dev / gamlss.dist

gamlss.dist: Distributions for Generalized Additive Models for Location Scale and Shape
https://CRAN.R-project.org/package=gamlss.dist
4 stars 3 forks source link

Fix problem with vector handling in ST3 derivatives #4

Open BerriJ opened 5 months ago

BerriJ commented 5 months ago

The ST3 derivatives enforce various bounds on the dsq1 and dsq2 objects using ifelse. However, ifelse poorly handles non-matching lengths of the inputs. Consider this example:

ifelse(TRUE, c(1, 2), c(3, 4))

This evaluates to 1.

Similarly in ST3()$dldm

w1 <- ifelse(tau < 1000000, (tau+1)/(tau+dsq1),1)
w2 <- ifelse(tau < 1000000, (tau+1)/(tau+dsq2),1)

Evaluate to the first element of the vector (tau+1)/(tau+dsq1) and (tau+1)/(tau+dsq2). I believe outputting the whole vectors (tau+1)/(tau+dsq1) and (tau+1)/(tau+dsq2) would be correct here. I suggest to fix that by repeating the input so that it matches the length of y which determines the length of dsq1 and dsq2. Like so: rep(tau, length(y)).

This is what this PR does.

Best regards, BerriJ