# [R] Covariance between two dichotomous variables

Greg Snow 538280 at gmail.com
Thu Sep 4 17:40:12 CEST 2014

```If you have 2 dichotomous variables coded 0/1 (and stored as numerics)
then the var and cov functions can be used to compute the covariance
as if they were continuous variables.  Some algebra shows that the
continous covariance and the binomial covariance only differ by the
denominator (n for binomial, n-1 for continuous), for large sample
sizes the difference is trivial, for small sample sizes (or even large
if you want) you can just multiply by (n-1)/n to correct.

On Tue, Sep 2, 2014 at 10:29 PM, Heather Kettrey
<heather.h.kettrey at vanderbilt.edu> wrote:
> Hi,
>
> I am trying to test a mediation hypothesis using coefficients from logistic
> regression analyses (x, m, and y are all dichotomous). I am running a test
> of significance using MacKinnon and Dwyer's adaptation of Sobel's test
> (i.e., correcting for different scales of coefficients in cases of a
> dichotomous outcome).
>
> In order to make this correction I need to compute the covariance between x
> and m. I have searched various R packages and the R-help page archive and
> cannot find a way to do this in R.
>
> Does anyone know how to compute the covariance between two dichotomous
> variables in R? It seems like there should be a very simple answer to this
> question, but I cannot find it.
>
> Thanks in advance!
>
> Heather
>
>
> --
> Heather Hensman Kettrey
> PhD Candidate
> Department of Sociology
> Vanderbilt University
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com

```

More information about the R-help mailing list