4
$\begingroup$

Lets say that I have "y" that I want to model with linear regression. "x" and "z" are the things I'm interrested in showing folks, but I also have things that I want to adjust for, but not really show in my plot.

Now, I would like to show my coefficients in a plot, but I would like to keep the things I adjusted for out of it. So perhaps this could be coronary artery calcification modeled as "CAC ~ SomeBloodStuff + Bloodpressure + BMI + Smoking_status". The BMI and Smoking_status would be something that I would want to take into account, but just note that I have adjusted for them.

I gather this is how to do the model:

MyModel <- lm( CAC ~ SomeBloodstuff + BP + BMI + Smoking_status, data=MyData)
summary(MyModel) 
coefficients(MyModel)
confint(MyModel, level=0.95) # Seems like a legit model.

The coefplot function in arm library gives just the sort of presentation that I want, but shows all the dimensions.

library(arm)
coefplot(MyModel)

How could I leave those few variables out of the plot while keeping them in the regression and get a plot that looks like what the coefplot produces?

$\endgroup$
2
  • $\begingroup$ You can't just ignore the variables that you've adjusted for. What you can do is set them to some value in the equation. The typical value to set them to is the sample mean. $\endgroup$ Commented Jul 10, 2014 at 21:12
  • 1
    $\begingroup$ I don't want to ignore them, but I just don't want to plot them, just note that I've adjusted for them. Am I misunderstanding something? $\endgroup$
    – ubongo
    Commented Jul 10, 2014 at 22:41

1 Answer 1

5
$\begingroup$

You can do what you're looking to do if you make fuller use of the coefplot package's optional arguments. In documentation, three relevant arguments are "predictors," "coefficients," and "strict":

predictors - A character vector specifying which variables to keep. Each individual variable has to be specfied [sic], so individual levels of factors must be specified. We are working on making this easier to implement, but this is the only option for now.

coefficients - A character vector specifying which factor variables to keep. It will keep all levels and any interactions, even if those are not listed.

strict - If TRUE then predictors will only be matched to its own coefficients, not its interactions [sic]

The following examples are selected from p. 8.

model1 <- lm(price ~ carat + cut*color, data=diamonds)

model2 <- lm(price ~ carat*color, data=diamonds)

model3 <- glm(price > 10000 ~ carat*color, data=diamonds)

coefplot(model1, predictors="color")

coefplot(model1, predictors="color", strict=TRUE)

coefplot(model1, coefficients=c("(Intercept)", "color.Q"))

coefplot(model1, predictors="cut", coefficients=c("(Intercept)", "color.Q"), strict=TRUE)
$\endgroup$
1
  • 2
    $\begingroup$ The coefplot from arm didn't have that functionality. Even though my question was propably a simple one, your help really made my day. Thanks a bunch! $\endgroup$
    – ubongo
    Commented Jul 11, 2014 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.