I have just discovered the Beta regression with Betareg package and I would like to see a full simple example using predict() and ploting the fitted regression curve(s) such as in figure 2 page 9 in the betareg vignette document (using the Gasoline yield data from Prater). The author's example (below) only gives the summary of the regression. http://cran.r-project.org/web/packages/betareg/vignettes/betareg.pdf.
data("GasolineYield", package = "betareg")
gy_logit <- betareg(yield ~ batch + temp, data = GasolineYield)
summary(gy_logit)
...
The exact code for the graphics in the betareg vignette can be easily queried from within R:
edit(vignette("betareg", package = "betareg"))
The gasoline example is in chunks 3-5. Alternatively, you can also look into the source code of the package on R-Forge https://R-Forge.R-project.org/scm/viewvc.php/pkg/vignettes/?root=betareg or use the copy on Github that Gregor pointed to.
If you want a ggplot2 version you can in princple use Sven's answer. However, it is in general not a good idea to fit the model on only a subset (batch == "6"). In this particular dataset, the estimated model is very similar to that fitted on the full data but for other datasets it might lead to inferior parameter estimates. Instead, estimate the full sample and then predict the effects by keeping some variables fixed and letting others vary. This is also what the effects package does (but unfortunately we have not set up a plugin for betareg and effects yet).
An approach with ggplot2:
First, fit the models for the data where batch == 6:
library(betareg)
data("GasolineYield", package = "betareg")
gy_logit <- betareg(yield ~ temp, data = GasolineYield, subset = batch == 6)
gy_loglog <- betareg(yield ~ temp, data = GasolineYield, subset = batch == 6,
link = "loglog")
Second, plot the data:
library(ggplot2)
ggplot(GasolineYield, aes(x = temp, y = yield)) +
geom_point(size = 4, aes(fill = batch), shape = 21) +
scale_fill_grey() +
geom_line(aes(y = predict(gy_loglog, GasolineYield),
colour = "log-log", linetype = "log-log")) +
geom_line(aes(y = predict(gy_logit, GasolineYield),
colour = "logit", linetype = "logit")) +
scale_colour_manual("", values = c("red", "blue")) +
scale_linetype_manual("", values = c("solid", "dashed")) +
theme_bw()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With