Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pearson correlation coefficient in R's survey package

Sorry if this is really obvious, but I can't see how to do a simple Pearson correlation between two variables in the survey package. My data has strata so it would be the equivalent to finding r for api00 and api99 in apistrat.

library(survey)
data(api)

dstrat <- svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)

I'm sure there must be a simple way of doing it using svyvar or svyglm or something but I can't see it?

like image 501
CWD Avatar asked Dec 22 '15 15:12

CWD


People also ask

What does Pearson's correlation coefficient tell you?

Pearson's correlation coefficient is the test statistics that measures the statistical relationship, or association, between two continuous variables. It is known as the best method of measuring the association between variables of interest because it is based on the method of covariance.

How does a correlation coefficient work in a survey?

Correlation is a statistic that measures the linear relationship between two variables (survey items). The numeric values for correlations are known as correlation coefficients and are commonly represented by the letter "r". The range of possible values for r is from -1.0 to +1.0.

What is the correlation coefficient in Rstudio?

Correlation coefficient is comprised between -1 and 1: -1 indicates a strong negative correlation : this means that every time x increases, y decreases (left panel figure) 0 means that there is no association between the two variables (x and y) (middle panel figure)


2 Answers

You can use svyvar to estimate the variance-covariance matrix, and then scale it to the correlation:

library(survey)
data(api)

dstrat <- svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
v <- svyvar(~api00+api99, dstrat)

as.matrix(v)
cov2cor(as.matrix(v))

This works for any number of correlations and any design.

like image 154
Thomas Lumley Avatar answered Oct 07 '22 13:10

Thomas Lumley


library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
summary(svyglm(api00~ell+meals+mobility, design=dstrat),correlation=T)
like image 34
Anthony Damico Avatar answered Oct 07 '22 12:10

Anthony Damico