## How to calculate confidence interval of mean response at a given level of continuous variable

Solved
Occasional Contributor
Posts: 10

# How to calculate confidence interval of mean response at a given level of continuous variable

[ Edited ]

Hi, I have a multiple regression model: y=x1+x2+e, where x1 is a continuous variable and x2 is a categorical variable (can either be fixed or random). I am trying to get a SE or Confidence interval for mean reponse at given level of x1, such as x1=20. But LSMEANS statement can only used for categorical variable

Edit on 8/19:

As the accepted solution stated, the BLUE can be estimated as

```lsmestimate sex 'Overall LS mean' 1 1 / at height=60 divisor=2 cl;
```

After some reading, I found another way to do it:

```Estimate 'Overall LS mean' intercept 1 height 60/cl;
```

This statement can also be used in model when the catergorical factor is random effect (sex in this case, although not proper to be treated as random).

Accepted Solutions
Solution
‎08-17-2016 02:59 PM
Posts: 5,043

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

Then, assuming that you want to give an equal weight to both sexes (in my example), you should request a least squares means estimate:

``````proc glimmix data=sashelp.class;
class sex;
model weight = height sex;
lsmestimate sex 'Overall LS mean' 1 1 / at height=60 divisor=2 cl;
run;``````

Use as many 1's as you have classes and the number of classes as divisor.

PG

All Replies
Super User
Posts: 11,767

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

[ Edited ]

Which regression procedure are you using?

It will help to see what your are currently doing and posting the code for the procedure answers many questions you may get asked.

Occasional Contributor
Posts: 10

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

[ Edited ]

Hi, either proc glm, groc glimmix or proc mixed are working the same.

proc glimmix;

model y=x1 x2; (if x2 is fixed)

model y=x1; random x2 ;(if x2 is random)

run;

I was trying to get the CI of estimated y at x=20 (or other value);

Super User
Posts: 11,767

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

Oneway: Add an OUTPUT statement requesting LCL and UCL or possibly LCLMu and UCLMu (probably should include PRED or PredMu as well). This output set will have every observation in the input set with the confidence limit at that point.

Select the values of X1 of interest afterwards.

Occasional Contributor
Posts: 10

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

The output gives pred and CI for each combination levels of x1*x2, such as x1=20 has different pred and CI at different level of x2. But what I want is the CI overall all x2.

Super User
Posts: 11,767

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

If you don't want both variables involved why are they on the model statement?

You may need to describe in more detail how you are intending to use the result as with multiple independent variables in a model there isn't really going to be a confidence limit for the predicted mean from just one variable and the interpretation might be odd.

Are you perhaps trying to take slices across the data?

Occasional Contributor
Posts: 10

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

With the 'model y=x3 x4;' if x3 and x4 are both catergorical var, lsmeans will give the pred and CI of x3 as main effect at mean level of x4, right? What is the interpretation of this CI then?

Does the meaning of CI different from what I am trying to get from the model y=x1 x2 while x1 is continuous?

Super User
Posts: 10,194

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

```I don't know. Maybe you should check EFFECTPLOT statement or EFFECT statement.

```
Posts: 5,043

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

LSMEANS are available for the levels of CLASS variables AT specified values of continuous predictors :

``````proc glimmix data=sashelp.class;
class sex;
model weight = height sex;
lsmeans sex / at height=60 cl;
run;``````

Are you looking for something else?

PG
Occasional Contributor
Posts: 10

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

I am not looking for the levels of CLASS variables AT specified values of continuous predictors.

I am looking for confidence interval of mean response  AT specified values of continuous predictors across all levels of the class variable (either fixed or random if fine).

Solution
‎08-17-2016 02:59 PM
Posts: 5,043

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

Then, assuming that you want to give an equal weight to both sexes (in my example), you should request a least squares means estimate:

``````proc glimmix data=sashelp.class;
class sex;
model weight = height sex;
lsmestimate sex 'Overall LS mean' 1 1 / at height=60 divisor=2 cl;
run;``````

Use as many 1's as you have classes and the number of classes as divisor.

PG
Occasional Contributor
Posts: 10

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

This looks like what I am trying to get! Thanks!

What if the catergorical variable is random effect?

Posts: 2,655

## Re: How to calculate confidence interval of mean response at a given level of continuous variable

Then it becomes a question of whether you want eBLUPs for each level of the categorical variable, or the marginal value over all levels of the random effect.  See this thread for an excellent discussion of how to get these.

BLUP and the 95% confidence interval of random effect in multilevel model

Steve Denham

☑ This topic is solved.