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?
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.
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.
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)
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With