calc_lhat_glm | R Documentation |
Calculates the optimal value of lhat for the prediction-powered confidence interval for GLMs.
calc_lhat_glm(
grads,
grads_hat,
grads_hat_unlabeled,
inv_hessian,
coord = NULL,
clip = FALSE
)
grads |
(matrix): n x p matrix gradient of the loss function with respect to the parameter evaluated at the labeled data. |
grads_hat |
(matrix): n x p matrix gradient of the loss function with respect to the model parameter evaluated using predictions on the labeled data. |
grads_hat_unlabeled |
(matrix): N x p matrix gradient of the loss function with respect to the parameter evaluated using predictions on the unlabeled data. |
inv_hessian |
(matrix): p x p matrix inverse of the Hessian of the loss function with respect to the parameter. |
coord |
(int, optional): Coordinate for which to optimize |
clip |
(boolean, optional): Whether to clip the value of lhat to be
non-negative. Defaults to |
(float): Optimal value of lhat
in [0,1].
dat <- simdat(model = "ols")
form <- Y - f ~ X1
X_l <- model.matrix(form, data = dat[dat$set_label == "labeled",])
Y_l <- dat[dat$set_label == "labeled", all.vars(form)[1]] |> matrix(ncol = 1)
f_l <- dat[dat$set_label == "labeled", all.vars(form)[2]] |> matrix(ncol = 1)
X_u <- model.matrix(form, data = dat[dat$set_label == "unlabeled",])
f_u <- dat[dat$set_label == "unlabeled", all.vars(form)[2]] |> matrix(ncol = 1)
est <- ppi_plusplus_ols_est(X_l, Y_l, f_l, X_u, f_u)
stats <- ols_get_stats(est, X_l, Y_l, f_l, X_u, f_u)
calc_lhat_glm(stats$grads, stats$grads_hat, stats$grads_hat_unlabeled,
stats$inv_hessian, coord = NULL, clip = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.