# \donttest{
require(gkwreg)
require(gkwdist)
data(FoodExpenditure)
FoodExpenditure$prop <- FoodExpenditure$food / FoodExpenditure$income
# Example 1: Basic Kumaraswamy regression
# Proportion spent on food decreases with income (Engel's law)
# Larger households spend more on food
fit_kw <- gkwreg(prop ~ income + persons,
data = FoodExpenditure,
family = "kw"
)
summary(fit_kw)
# Interpretation:
# - Alpha: Negative income effect (Engel's law)
# Positive household size effect
# - Beta: Constant precision (homoscedastic model)
# Example 2: Heteroscedastic model
# Variability in food proportion may differ by income and household size
fit_kw_hetero <- gkwreg(
prop ~ income + persons |
income + persons,
data = FoodExpenditure,
family = "kw"
)
summary(fit_kw_hetero)
# Interpretation:
# - Beta: Precision varies with both income and household size
# Wealthier or larger households may show different spending variability
# Test for heteroscedasticity
anova(fit_kw, fit_kw_hetero)
# Example 3: Exponentiated Kumaraswamy for extreme spending patterns
# Some households may have unusual food spending (very frugal or lavish)
fit_ekw <- gkwreg(
prop ~ income + persons | # alpha
persons | # beta: household size affects precision
income, # lambda: income affects extremity
data = FoodExpenditure,
family = "ekw"
)
summary(fit_ekw)
# Interpretation:
# - Lambda: Income level affects tail behavior
# Rich households may show more extreme (unusual) spending patterns
# Visualization: Engel curve
plot(prop ~ income,
data = FoodExpenditure,
xlab = "Annual Income ($)", ylab = "Proportion Spent on Food",
main = "Engel Curve for Food Expenditure"
)
# Add fitted values
FoodExpenditure$fitted_kw <- fitted(fit_kw)
points(FoodExpenditure$income, FoodExpenditure$fitted_kw,
col = "blue", pch = 19, cex = 0.8
)
legend("topright",
legend = c("Observed", "Fitted"),
col = c("black", "blue"), pch = c(1, 19)
)
# }
Run the code above in your browser using DataLab