Learn R Programming

RRreg (version 0.1.3)

RRcor: Bivariate correlations including randomized response variables

Description

RRcor calculates bivariate Pearson correlations of variables measured with or without RR.

Usage

RRcor(x, y = NULL, models, p.list, group = NULL, bs.n = 0,
  bs.type = c("n", "p"), nCPU = 1)

Arguments

x
a numeric vector, matrix or data frame.
y
NULL (default) or a vector, matrix or data frame with compatible dimensions to x.
models
a vector defining which RR design is used for each variable. Must be in the same order as variables appear in x and y (by columns). Available models: Warner, Kuk, FR, Mangat,
p.list
a list containing the randomization probabilities of the RR models defined in models. Either, all direct-variables (i.e., no randomized response) in models can be excluded in p.list; or, if
group
a matrix defining the group membership of each participant (values 1 and 2) for all multiple group models(SLD, UQTunknown). If only one of these models is included in models, a vector can be used. For more than one m
bs.n
number of samples used to get bootstrapped standard errors
bs.type
Choose between parametric (p) and/or nonparametric (n) bootstrap to obtain standard errors (note: bs.n has to be larger than 0). The parametric bootstrap is based on the assumption, that the continuous variable is no
nCPU
number of CPUs used for the bootstrap

Value

  • an object RRcor, can be analyzed by means of summary. Use object$r to get the correlation matrix only.

Details

Correlations of RR variables are calculated by the method of Fox & Tracy (1984) by interpreting the variance induced by the RR procedure as uncorrelated measurement error. Since the error is independent, the correlation can be corrected to obtain an unbiased estimator.

References

Fox, J. A., & Tracy, P. E. (1984). Measuring associations with randomized response. Social Science Research, 13, 188-197.

See Also

vignette('RRreg') or https://dl.dropboxusercontent.com/u/21456540/RRreg/index.html for a detailed description of the RR models and the appropriate definition of p

Examples

Run this code
# generate first RR variable
n <-1000
p1 <- c(.4,.6)
gData <- RRgen(n,pi=.3,model="Kuk",p1)
n1 <- table(gData$true)[1]
gData[gData$true==0,4] <-  rnorm(n1)
gData[gData$true==1,4] <-  rnorm(n-n1,mean=0.7)

# generate second RR variable
p2 <- c(.7,.4)
temp <- RRgen(n1,pi=.2,model="UQTknown",p2)
gData$uqtResponse[gData$true==0] <- temp$response
gData$uqtTrue[gData$true==0] <- temp$true
temp <- RRgen(n-n1,pi=.7,model="Kuk",p2)
gData$uqtResponse[gData$true==1] <- temp$response
gData$uqtTrue[gData$true==1] <- temp$true

# show true correlation
cor(gData[,c("true","V4","uqtTrue")])
# estimated correlation
RRcor(x=gData[,c("response","V4","uqtTrue")],models=c("Kuk","d","UQTknown"),p.list= list(p1,p2) )

Run the code above in your browser using DataLab