Looking for advice on a package in R or Python and an approach to help me construct a confidence interval for a marginal mean (or maybe we'll call it a prediction).
Say I run OLS regression with $y$ as my dependent variable and $X_1$ as my design matrix. I would like to add new observations to $X_1$, say $X_2$, to create $X_{new}$. I would like to construct a confidence/prediction interval for the mean of $X_{new}$ using my original model. I am aware that prediction intervals are wider than confidence intervals. Can I:
- Calculate the means of the variables in $X_{new}$, and plug those means into my linear model and construct a prediction interval? It would be as if I'm treating the means of $X_{new}$ as a new observation.
- Do I want to use something like
emmeans
in R, ormargins
in Stata?
$X_2$ is sort of similar to $X_1$, so it's not like I'm trying to wildly extrapolate, it's just that $X_2$ wasn't used to build the model (because I don't have $y$ values for $X_2$).
predict(my.lm, newdata = X2, interval = "pred")
wheremy.lm
is the model fitted to x1 andX2
is a data frame with your x2 vales. $\endgroup$ – Russ Lenth Aug 1 '20 at 0:35interval = "conf"
. My previous comment is based on predicting future y values. $\endgroup$ – Russ Lenth Aug 1 '20 at 17:27