pbreheny / visreg

Visualization of regression functions
http://pbreheny.github.io/visreg/
61 stars 18 forks source link

visreg+betareg #90

Open VitoMuggeo opened 3 years ago

VitoMuggeo commented 3 years ago

I get the plot from betareg fit (from package betareg), but without the confidence interval bands. vcov() and predict.betareg() do exist and work correctly on a betareg object, but predict.betareg() apparentely misses the "se.fit" argument.. I think that is the problem. thanks, vito

PS Adding an option "vcov" in visreg() to supply a specified vcov matrix (without relying on the predict method) would fix that, I think.

pbreheny commented 3 years ago

Hi Vito,

This has come up in other situations (see #89), and in the next version of visreg, I'll be adding a predict= argument and a residuals= argument to allow users to customize the predict() function, especially useful if it has extra options or nonstandard syntax.

In the meantime, a workaround is to define your own predict.betareg() function that will then be called instead of the package's. So, something along the lines of:

predict.betareg <- function(object, newdata, se.fit=FALSE, ...) {
  if (se.fit) {
    return(list(fit=betareg:::predict.betareg(object, newdata, type="link"),
                se.fit=XXX)) # You'd have to calculate your own SE here, if betareg doesn't provide it
  } else {
    return(betareg:::predict.betareg(object, newdata, type="link"))
  }
}

I'm not familiar with the betareg package, so I'm not sure how easy this SE calculation is, but yes, presumably it is possible to use vcov to calculate the required SE.

If you do write a predict.betareg() function that works, let me know and I can add it to visreg, although really, I would argue that it should be added to betareg instead.

VitoMuggeo commented 3 years ago

Hi Patrick, Thanks for your reply and comments. I will get back to you when I have
some good news.. :-)

best, vito