2
$\begingroup$

I would like to know if it is possible to create a scatterplot while controlling for covariates, such as in partial correlation. I am using R software and my code is below for the basic scatterplot.

I am not interested in multiple lines of best fit or multiple scatters per graph. I am also not interested in creating a lattice of scatterplots with all of the variables.

I can't seem to find any code that will allow me to parse the effect of the covariates from my x-y scatterplot. All three covariates are continuous. Any ideas would be helpful.

plot(pmc$reject, pmcp$LPA, main="r(Parenting, Left Amygdala)",
    xlab="Parenting Age 2", ylab="Amygdala Reactivity Age 15", pch=19)
abline(lm(pmc$reject ~ pmcp$LPA), col="red") # regression line (y~x)
$\endgroup$
2
  • 2
    $\begingroup$ One way would be to fit a regression model using all covariates, and then predict y values for x using some fixed value for all the covariates (either the mean, or the most common value for factors). This can be done with predict(). $\endgroup$
    – MrFlick
    Commented Jun 30, 2014 at 19:04
  • 2
    $\begingroup$ Please consider adding a minimal example dataset for pmcp. $\endgroup$ Commented Jun 30, 2014 at 19:16

1 Answer 1

1
$\begingroup$

As said in comments, one way would be to fit a regression model, and then plot predictions with some covariates hold at fixed values, and the one used on the x-axis with its observed values. The Rpackage effects (on CRAN) can be useful.

Another idea, especially with three variables (but combined with the above ideas could be used with more) is conditioning plots, made in R with the function coplot. On this site some examples can be found here, used for investigating interactions, another example with R dataset swiss, and used for investigating conditional correlations, or search this site.

Finally, one example, showing conditional correlations, from the post Can I analyze or model a conditional correlation?

a conditional correlations coplot

$\endgroup$

Your Answer

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