1
$\begingroup$

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, or margins 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$).

$\endgroup$
4
  • 1
    $\begingroup$ Seems to me all you need is predict(my.lm, newdata = X2, interval = "pred") where my.lm is the model fitted to x1 and X2 is a data frame with your x2 vales. $\endgroup$ – Russ Lenth Aug 1 '20 at 0:35
  • $\begingroup$ Thank you! Splitting hairs here...but do you think that this interval will be slightly conservative since it's a prediction interval, which are slightly wider than confidence intervals, and since some of my data (X1) was used to build the model? OR do you think the fact that I'm sort of extrapolating vastly overshadows the minor differences between interval types? $\endgroup$ – Alex Aug 1 '20 at 17:07
  • 1
    $\begingroup$ If your goal is to estimate E(y|X2), then use interval = "conf". My previous comment is based on predicting future y values. $\endgroup$ – Russ Lenth Aug 1 '20 at 17:27
  • $\begingroup$ My goal is $E(y|X_{new})$, where $X_{new}$ is $X_1$ stacked with $X_2$ - a blend of "seen" and "unseen" data. $\endgroup$ – Alex Aug 1 '20 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.