参考我的问题this和this,有人建议我应用岭回归,然后应用beta回归。因为我无法计算Beta Ridge Regression。这是正确的方法吗,我对此感到困惑。请检查以下代码并提出建议......
代码
library(glmnet)
library(betareg)
# Generate some simulated data with high multicollinearity
set.seed(123)
n <- 100
x1 <- rnorm(n, 0, 1)
x2 <- 0.5*x1 + rnorm(n, 0, 0.5)
x3 <- 0.5*x1 + 0.5*x2 + rnorm(n, 0, 0.5)
y <- rbeta(n, 1, 1)
data <- data.frame(x1, x2, x3, y)
# Stage 1: Ridge regression to reduce multicollinearity
fit_ridge <- glmnet(x = model.matrix(y ~ x1 + x2 + x3, data = data),
y = data$y,
alpha = 0, # set alpha = 0 for ridge regression
lambda = 0.1)
# Extract the coefficients from the ridge regression
coef_ridge <- coef(fit_ridge, s = 0.1)[-1]
# Create a reduced data set with the ridge regression coefficients
data_reduced <- data.frame(model.matrix(y ~ x1 + x2 + x3, data = data) %*% coef_ridge, y)
# Stage 2: Beta regression with reduced data set
fit_beta <- betareg(y ~ ., data = data_reduced)
# Print the coefficients
coef(fit_beta)
杰克!我有和你类似的问题,我正在尝试将 beta 回归与岭回归混合,但我还没有找到一个好的解决方案,你设法解决这个问题了吗?