diff --git a/.Rbuildignore b/.Rbuildignore index 2cd967a..508c046 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,6 @@ README.md ^docs$ _pkgdown.yml ^_pkgdown\.yml$ +^CRAN-RELEASE$ +^cran-comments\.md$ +^CRAN-SUBMISSION$ diff --git a/.gitignore b/.gitignore index e99b950..985cc56 100644 --- a/.gitignore +++ b/.gitignore @@ -13,8 +13,6 @@ vignettes/*.html vignettes/*.pdf .Rproj.user -*.Rproj - # compiled files src/*.o src/*.so diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION new file mode 100644 index 0000000..34e0996 --- /dev/null +++ b/CRAN-SUBMISSION @@ -0,0 +1,3 @@ +Version: 1.4.1 +Date: 2022-05-24 02:06:53 UTC +SHA: 3b92e9e126af50a898da86d33da08f7354e9682a diff --git a/ChangeLog b/ChangeLog index 0d417ce..3ef627e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,4 +4,5 @@ version date description 1.2 03/21/15 Added Bayesian implementation for forced response design, including mixed effects option. 1.3 03/26/15 Bug fixes 1.3.1 05/13/16 Compatibility with package dependencies -1.4 08/15/16 Added functionality for including auxiliary information by generalized method of moments \ No newline at end of file +1.4 08/15/16 Added functionality for including auxiliary information by generalized method of moments +1.4.1 05/23/22 Changes to stay up to date on CRAN \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 3ce4b21..157417e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,11 +1,10 @@ Package: rr -Version: 1.5 -Date: 2017-8-11 +Version: 1.4.1 Title: Statistical Methods for the Randomized Response Technique -Authors@R: c(person("Graeme", "Blair", email = "graeme.blair@ucla.edu", role = c("aut", "cre")), - person("Yang-Yang", "Zhou", email = "yz3@princeton.edu", role = c("aut")), - person("Kosuke", "Imai", email = "kimai@princeton.edu", role = c("aut")), - person("Winston", "Chou", email = "macartan@gmail.com", role = c("ctb"))) +Authors@R: c(person("Graeme", "Blair", email = "graeme.blair@gmail.com", role = c("aut", "cre")), + person("Yang-Yang", "Zhou", email = "yangyang.zhou@ubc.ca", role = c("aut")), + person("Kosuke", "Imai", email = "imai@harvard.edu", role = c("aut")), + person("Winston", "Chou", email = "wchou@princeton.edu", role = c("ctb"))) Depends: R (>= 3.0.0), utils @@ -23,10 +22,11 @@ Description: Enables researchers to conduct multivariate statistical analyses are included. The package implements methods described in Blair, Imai, and Zhou (2015) ''Design and Analysis of the Randomized Response Technique,'' Journal of the American Statistical Association - . + . LazyLoad: yes LazyData: yes License: GPL (>= 3) Suggests: testthat -RoxygenNote: 6.0.1 +Encoding: UTF-8 +RoxygenNote: 7.1.2 diff --git a/NAMESPACE b/NAMESPACE index 984d648..67e4f31 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ S3method(coef,rrreg.bayes) S3method(coef,rrreg.bayes.list) S3method(coef,rrreg.predictor) S3method(predict,rrreg) +S3method(predict,rrreg.predictor) S3method(print,rrreg) S3method(print,rrreg.bayes) S3method(print,rrreg.predictor) diff --git a/R/onAttach.R b/R/onAttach.R deleted file mode 100644 index e69de29..0000000 diff --git a/R/power.R b/R/power.R index 0fb4b95..53f3899 100644 --- a/R/power.R +++ b/R/power.R @@ -78,7 +78,7 @@ #' @references Blair, Graeme, Kosuke Imai and Yang-Yang Zhou. (2015) "Design #' and Analysis of the Randomized Response Technique." \emph{Journal of the #' American Statistical Association.} -#' Available at \url{http://graemeblair.com/papers/randresp.pdf}. +#' Available at \url{https://graemeblair.com/papers/randresp.pdf}. #' @keywords power analysis #' @examples #' @@ -92,28 +92,6 @@ #' design = "forced-known", sig.level = .01, #' type = "one.sample", alternative = "one.sided") #' -#' \dontrun{ -#' -#' ## Find power varying the number of respondents from 250 to 2500 and -#' ## the population proportion of respondents possessing the sensitive -#' ## trait from 0 to .15 -#' -#' presp.seq <- seq(from = 0, to = .15, by = .0025) -#' n.seq <- c(250, 500, 1000, 2000, 2500) -#' power <- list() -#' for(n in n.seq) { -#' power[[n]] <- rep(NA, length(presp.seq)) -#' for(i in 1:length(presp.seq)) -#' power[[n]][i] <- power.rr.test(p = 2/3, p1 = 1/6, p0 = 1/6, n = n, -#' presp = presp.seq[i], presp.null = 0, -#' design = "forced-known", sig.level = .01, -#' type = "one.sample", -#' alternative = "one.sided")$power -#' } -#' -#' ## Replicates the results for Figure 2 in Blair, Imai, and Zhou (2014) -#' } -#' #' @export power.rr.test <- function(p, p0, p1, q, design, n = NULL, r, presp, presp.null = NULL, sig.level, prespT, prespC, prespT.null = NULL, prespC.null, @@ -576,6 +554,9 @@ se.f.rr <- function(p, p0, p1, q, design, n, r, presp){ #' and Analysis of the Randomized Response Technique." \emph{Working Paper.} #' Available at \url{http://imai.princeton.edu/research/randresp.html}. #' @keywords power analysis +#' +#' @return Power curve plot +#' #' @examples #' #' ## Generate a power plot for the forced design with known @@ -584,7 +565,6 @@ se.f.rr <- function(p, p0, p1, q, design, n, r, presp){ #' ## 250 to 2500 and the population proportion of respondents #' ## possessing the sensitive trait from 0 to .15. #' -#' #' presp.seq <- seq(from = 0, to = .15, by = .0025) #' n.seq <- c(250, 500, 1000, 2000, 2500) #' power.rr.plot(p = 2/3, p1 = 1/6, p0 = 1/6, n.seq = n.seq, @@ -655,8 +635,11 @@ power.rr.plot <- function(p, p0, p1, q, design, n.seq, r, presp.seq, presp.null } } - if(par == TRUE) - par(oma = c(0, 0, 0, 0), mar = c(3.6, 3.6, 0, 0), las = 1, mgp = c(2, .7, 0), tck = -.01, cex = 0.8) + if(par == TRUE) { + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) + par(oma = c(0, 0, 0, 0), mar = c(3.6, 3.6, 0, 0), las = 1, mgp = c(2, .7, 0), tck = -.01, cex = 0.8) + } plot(0, 1, type = "n", xlim = c(0, max(presp.seq)), ylim = c(0, 1.05), axes = F, xlab = "", ylab = "") diff --git a/R/rr-package.R b/R/rr-package.R index d095737..0fd163b 100644 --- a/R/rr-package.R +++ b/R/rr-package.R @@ -25,19 +25,19 @@ #' @aliases rr-package rr #' @docType package #' @author Graeme Blair, Experiments in Governance and Politics, Columbia -#' University \email{graeme.blair@@columbia.edu}, \url{http://graemeblair.com} +#' University \email{graeme.blair@@gmail.com}, \url{https://graemeblair.com} #' -#' Kosuke Imai, Department of Politics, Princeton University -#' \email{kimai@@princeton.edu}, \url{http://imai.princeton.edu} +#' Kosuke Imai, Departments of Government and Statistics, Harvard University +#' \email{kimai@@harvard.edu}, \url{https://imai.fas.harvard.edu} #' -#' Yang-Yang Zhou, Department of Politics, Princeton University -#' \email{yz3@@princeton.edu}, \url{http://yangyangzhou.com} +#' Yang-Yang Zhou, Department of Political Science, University of British Columbia +#' \email{yangyang.zhou@@ubc.ca}, \url{https://www.yangyangzhou.com} #' -#' Maintainer: Graeme Blair +#' Maintainer: Graeme Blair #' @references Blair, Graeme, Kosuke Imai and Yang-Yang Zhou. (2015) "Design #' and Analysis of the Randomized Response Technique." #' \emph{Journal of the American Statistical Association.} -#' Available at \url{http://graemeblair.com/papers/randresp.pdf}. +#' Available at \url{https://graemeblair.com/papers/randresp.pdf}. #' @keywords package #' @importFrom graphics abline axis lines mtext plot #' @importFrom stats as.formula binomial coef complete.cases cov dcauchy df glm glm.control model.frame model.matrix model.matrix.default model.response na.omit pnorm qnorm quantile rnorm runif sd vcov diff --git a/R/rr.R b/R/rr.R index 5050d9e..8da8b75 100644 --- a/R/rr.R +++ b/R/rr.R @@ -586,6 +586,7 @@ coef.rrreg <- function(object, ...){ #' @param keep.draws Option to return the Monte Carlos draws of the quantity of #' interest, for use in calculating differences for example. #' @param ... Further arguments to be passed to \code{predict.rrreg()} command. +#' #' @return \code{predict.rrreg} returns predicted probabilities either for each #' observation in the data frame or the average over all observations. The #' output is a list that contains the following components: @@ -611,7 +612,6 @@ coef.rrreg <- function(object, ...){ #' @keywords predicted probabilities fitted values #' @examples #' -#' \dontrun{ #' data(nigeria) #' #' set.seed(1) @@ -637,7 +637,6 @@ coef.rrreg <- function(object, ...){ #' n.sims = 10000) #' #' ## Replicates Table 3 in Blair, Imai, and Zhou (2014) -#' } #' #' @importFrom MASS mvrnorm #' diff --git a/R/rrBayes.R b/R/rrBayes.R index f7b3392..a2e3375 100644 --- a/R/rrBayes.R +++ b/R/rrBayes.R @@ -119,12 +119,13 @@ logistic <- function(x) exp(x)/(1+exp(x)) #' data = nigeria, #' p = p, p1 = p1, p0 = p0, #' design = "forced-known") +#' +#' \donttest{ #' #' library(MASS) #' draws <- mvrnorm(n = 3, mu = coef(mle.estimates), #' Sigma = vcov(mle.estimates) * 9) #' -#' \dontrun{ #' ## run three chains #' bayes.1 <- rrreg.bayes(rr.q1 ~ cov.asset.index + cov.married + #' I(cov.age/10) + I((cov.age/10)^2) + cov.education + cov.female, @@ -146,6 +147,7 @@ logistic <- function(x) exp(x)/(1+exp(x)) #' bayes <- as.list(bayes.1, bayes.2, bayes.3) #' #' summary(bayes) +#' #' } #' #' @importFrom coda mcmc @@ -211,7 +213,7 @@ rrreg.bayes <- function(formula, p, p0, p1, design, data, if(!(group.mixed %in% colnames(data))) stop("The covariate named in group.mixed cannot be found in the provided data frame.") grp <- data[na.cond == TRUE, paste(group.mixed)] - if(class(grp) == "character") + if(inherits(grp, "character")) grp <- as.factor(grp) grp.labels <- sort(unique(grp)) @@ -239,11 +241,11 @@ rrreg.bayes <- function(formula, p, p0, p1, design, data, if (missing("beta.tune")) { stop("The Metropolis tuning input object beta.tune is required.") - } else if (class(beta.tune) == "numeric" & length(beta.tune) == 1 & nPar > 1) { + } else if (inherits(beta.tune, "numeric") & length(beta.tune) == 1 & nPar > 1) { beta.tune <- diag(nPar) * beta.tune - } else if (class(beta.tune) == "numeric" & length(beta.tune) == nPar) { + } else if (inherits(beta.tune, "numeric") & length(beta.tune) == nPar) { beta.tune <- diag(beta.tune) - } else if (class(beta.tune) == "numeric" | (class(beta.tune) == "matrix" & + } else if (inherits(beta.tune, "numeric") | (inherits(beta.tune, "matrix") & (ncol(beta.tune) != nPar | nrow(beta.tune) != nPar))) { stop("The input beta.tune is malformed. It should be a scalar, a vector of length the number of predictors, or a diagonal matrix of dimensions the number of predictors.") } @@ -252,10 +254,10 @@ rrreg.bayes <- function(formula, p, p0, p1, design, data, if (missing("Psi.start")) { Psi.start <- diag(10, ncol(z)) - } else if (class(Psi.start) == "numeric" & + } else if (inherits(Psi.start, "numeric") & (length(Psi.start) == 1 | length(Psi.start) == ncol(z))) { Psi.start <- diag(ncol(z)) * Psi.start - } else if (class(Psi.start) == "numeric" | (class(Psi.start) == "matrix" & + } else if (inherits(Psi.start, "numeric") | (inherits(Psi.start, "matrix") & (nrow(Psi.start) != ncol(z) | ncol(Psi.start) != ncol(z)))) { stop("The input Psi.start is malformed. It should either be a square matrix of dimensions the number of columns of Z, a scalar, or a vector of length number of columns of Z.") } @@ -265,19 +267,19 @@ rrreg.bayes <- function(formula, p, p0, p1, design, data, } if (missing("Psi.scale")) { Psi.scale <- diag(2, ncol(z)) - } else if (class(Psi.scale) == "numeric" & + } else if (inherits(Psi.scale, "numeric") & (length(Psi.scale) == 1 | length(Psi.scale) == ncol(z))) { Psi.scale <- diag(ncol(z)) * Psi.scale - } else if (class(Psi.scale) == "numeric" | (class(Psi.scale) == "matrix" & + } else if (inherits(Psi.scale, "numeric") | (inherits(Psi.scale, "matrix") & (nrow(Psi.scale) != ncol(z) | ncol(Psi.scale) != ncol(z)))) { stop("The input Psi.scale is malformed. It should either be a square matrix of dimensions the number of columns of Z, a scalar, or a vector of length number of columns of Z.") } if (missing("Psi.tune")) { stop("The Metropolis tuning input object psi.tune is required.") - } else if (class(Psi.tune) == "numeric" & length(Psi.tune) == 1 & length(unique(grp)) > 1) { + } else if (inherits(Psi.tune, "numeric") & length(Psi.tune) == 1 & length(unique(grp)) > 1) { Psi.tune <- rep(Psi.tune, length(unique(grp))) - } else if (class(Psi.tune) == "matrix" | (class(Psi.tune) == "numeric" & (length(Psi.tune) != length(unique(grp))))) { + } else if (inherits(Psi.tune, "matrix") | (inherits(Psi.tune, "numeric") & (length(Psi.tune) != length(unique(grp))))) { stop("The input Psi.tune is malformed. It should be either a scalar or a vector of length the number of groups.") } } diff --git a/R/rrreg.predictor.R b/R/rrreg.predictor.R index d7d0b76..7755931 100644 --- a/R/rrreg.predictor.R +++ b/R/rrreg.predictor.R @@ -118,7 +118,6 @@ logistic <- function(x) exp(x)/(1+exp(x)) #' #' ## Fit joint model of responses to an outcome regression of joining a civic #' ## group and the randomized response item of having a militant social connection -#' \dontrun{ #' rr.q1.pred.obj <- #' rrreg.predictor(civic ~ cov.asset.index + cov.married + I(cov.age/10) + #' I((cov.age/10)^2) + cov.education + cov.female @@ -127,7 +126,7 @@ logistic <- function(x) exp(x)/(1+exp(x)) #' p = p, p1 = p1, p0 = p0, design = "forced-known") #' #' summary(rr.q1.pred.obj) -#' } +#' #' ## Replicates Table 4 in Blair, Imai, and Zhou (2014) #' #' @importFrom arm bayesglm @@ -518,7 +517,7 @@ print.summary.rrreg.predictor <- function(x, ...){ #' unrelated question. The design, already specified in the "rrreg.predictor" #' object, is then directly inputted into this function. #' -#' @usage predict.rrreg.predictor(object, fix.z = NULL, alpha = .05, +#' @usage \method{predict}{rrreg.predictor}(object, fix.z = NULL, alpha = .05, #' n.sims = 1000, avg = FALSE, newdata = NULL, quasi.bayes = FALSE, keep.draws #' = FALSE, ...) #' @param object An object of class "rrreg.predictor" generated by the @@ -571,11 +570,11 @@ print.summary.rrreg.predictor <- function(x, ...){ #' @keywords predicted probabilities fitted values #' @examples #' -#' \dontrun{ #' data(nigeria) #' #' ## Define design parameters #' +#' \donttest{ #' set.seed(44) #' #' p <- 2/3 # probability of answering honestly in Forced Response Design @@ -597,11 +596,11 @@ print.summary.rrreg.predictor <- function(x, ...){ #' #' rr.q1.rrreg.predictor.pred <- predict(rr.q1.pred.obj, #' avg = TRUE, quasi.bayes = TRUE, -#' n.sims = 10000) -#' +#' n.sims = 1000) #' } #' @importFrom MASS mvrnorm #' @method predict rrreg.predictor +#' @export predict.rrreg.predictor <- function(object, fix.z = NULL, alpha = .05, n.sims = 1000, avg = FALSE, newdata = NULL, quasi.bayes = FALSE, keep.draws = FALSE, ...) { diff --git a/cran-comments.md b/cran-comments.md new file mode 100644 index 0000000..5d5d69a --- /dev/null +++ b/cran-comments.md @@ -0,0 +1,25 @@ +## Submission + +(Resubmitting with minor change to remove rm(list=ls()) per email from Victoria.) + +We are submitting this patch to address the USE_FC_LEN_T issue identified in Ripley's April 5 email. We apologize for the delay in submission and realize it resulted in the package getting pulled. + +In addition, the email address for the maintainer has been updated and some other minor changes caught by R CMD CHECK. + +Thank you! + +## Test environments +* local OS X install, R 3.5.1 +* ubuntu 12.04 (on travis-ci), R 3.5.1 +* win-builder (devel and release) + +## R CMD check results + +0 errors | 0 warnings | 0 notes + +## Reverse dependencies + +There are no reverse dependencies. + +--- + diff --git a/inst/CITATION b/inst/CITATION index a263588..9d7a946 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -1,17 +1,17 @@ -citHeader("To cite list in publications use:") - -citEntry(entry = "misc", - title = "{rr}: Statistical Methods for the Randomized Response Technique", - author = personList(as.person("Graeme Blair"), as.person("Yang-Yang Zhou"), - as.person("Kosuke Imai")), - howpublished = "Available at The Comprehensive R Archive Network (CRAN)", - year = "2015", - url = "http://CRAN.R-project.org/package=rr", - - textVersion = - paste("Graeme Blair, Yang-Yang Zhou, and Kosuke Imai (2015).", - "rr: Statistical Methods for the Randomized Response Technique.", - "Available at The Comprehensive R Archive Network (CRAN).", - "URL http://CRAN.R-project.org/package=rr.") -) - +citHeader("To cite list in publications use:") + +citEntry(entry = "misc", + title = "{rr}: Statistical Methods for the Randomized Response Technique", + author = personList(as.person("Graeme Blair"), as.person("Yang-Yang Zhou"), + as.person("Kosuke Imai")), + howpublished = "Available at The Comprehensive R Archive Network (CRAN)", + year = "2015", + url = "https://CRAN.R-project.org/package=rr", + + textVersion = + paste("Graeme Blair, Yang-Yang Zhou, and Kosuke Imai (2015).", + "rr: Statistical Methods for the Randomized Response Technique.", + "Available at The Comprehensive R Archive Network (CRAN).", + "URL https://CRAN.R-project.org/package=rr") +) + diff --git a/man/nigeria-data.Rd b/man/nigeria-data.Rd index 18153bd..0707c6e 100644 --- a/man/nigeria-data.Rd +++ b/man/nigeria-data.Rd @@ -4,7 +4,8 @@ \alias{nigeria-data} \title{Nigeria Randomized Response Survey Experiment on Social Connections to Armed Groups} -\format{A data frame containing 2457 observations. The variables are: +\format{ +A data frame containing 2457 observations. The variables are: \itemize{ \item \code{Quesid}: Survey ID of civilian respondent. \item \code{rr.q1}: Randomized response survey item using the Forced Response Design asking the respondent whether they hold direct social connections @@ -21,7 +22,8 @@ university; 9 if finished university; 10 if received graduate (masters or Ph.D) education. \item \code{cov.female}: Gender. 0 if male; 1 if female. \item \code{civic}: Whether or not the respondent is a member of a civic group in their communities, such as youth groups , women's groups, or -community development committees. }} +community development committees. } +} \source{ Blair, Graeme, Kosuke Imai and Yang-Yang Zhou. (2014) Replication data for: Design and Analysis of the Randomized Response Technique. diff --git a/man/power.rr.plot.Rd b/man/power.rr.plot.Rd index f1418d1..5223974 100644 --- a/man/power.rr.plot.Rd +++ b/man/power.rr.plot.Rd @@ -86,6 +86,9 @@ The default is \code{TRUE}.} \item{...}{Additional arguments to be passed to \code{par()}} } +\value{ +Power curve plot +} \description{ \code{power.rr.plot} generates a power analysis plot for randomized response survey designs. @@ -106,7 +109,6 @@ sample sizes are shown as different lines in grayscale. ## 250 to 2500 and the population proportion of respondents ## possessing the sensitive trait from 0 to .15. - presp.seq <- seq(from = 0, to = .15, by = .0025) n.seq <- c(250, 500, 1000, 2000, 2500) power.rr.plot(p = 2/3, p1 = 1/6, p0 = 1/6, n.seq = n.seq, diff --git a/man/power.rr.test.Rd b/man/power.rr.test.Rd index 68d6273..b633693 100644 --- a/man/power.rr.test.Rd +++ b/man/power.rr.test.Rd @@ -115,34 +115,12 @@ power.rr.test(p = 2/3, p1 = 1/6, p0 = 1/6, n = 200, design = "forced-known", sig.level = .01, type = "one.sample", alternative = "one.sided") -\dontrun{ - -## Find power varying the number of respondents from 250 to 2500 and -## the population proportion of respondents possessing the sensitive -## trait from 0 to .15 - -presp.seq <- seq(from = 0, to = .15, by = .0025) -n.seq <- c(250, 500, 1000, 2000, 2500) -power <- list() -for(n in n.seq) { - power[[n]] <- rep(NA, length(presp.seq)) - for(i in 1:length(presp.seq)) - power[[n]][i] <- power.rr.test(p = 2/3, p1 = 1/6, p0 = 1/6, n = n, - presp = presp.seq[i], presp.null = 0, - design = "forced-known", sig.level = .01, - type = "one.sample", - alternative = "one.sided")$power - } - -## Replicates the results for Figure 2 in Blair, Imai, and Zhou (2014) -} - } \references{ Blair, Graeme, Kosuke Imai and Yang-Yang Zhou. (2015) "Design and Analysis of the Randomized Response Technique." \emph{Journal of the American Statistical Association.} -Available at \url{http://graemeblair.com/papers/randresp.pdf}. +Available at \url{https://graemeblair.com/papers/randresp.pdf}. } \keyword{analysis} \keyword{power} diff --git a/man/predict.rrreg.Rd b/man/predict.rrreg.Rd index 2e6a893..853496b 100644 --- a/man/predict.rrreg.Rd +++ b/man/predict.rrreg.Rd @@ -71,7 +71,6 @@ then directly inputted into this function. } \examples{ -\dontrun{ data(nigeria) set.seed(1) @@ -97,7 +96,6 @@ rr.q1.reg.pred <- predict(rr.q1.reg.obj, given.y = FALSE, n.sims = 10000) ## Replicates Table 3 in Blair, Imai, and Zhou (2014) -} } \references{ diff --git a/man/predict.rrreg.predictor.Rd b/man/predict.rrreg.predictor.Rd index c4c5abc..2e65383 100644 --- a/man/predict.rrreg.predictor.Rd +++ b/man/predict.rrreg.predictor.Rd @@ -4,7 +4,7 @@ \alias{predict.rrreg.predictor} \title{Predicted Probabilities for Randomized Response as a Regression Predictor} \usage{ -predict.rrreg.predictor(object, fix.z = NULL, alpha = .05, +\method{predict}{rrreg.predictor}(object, fix.z = NULL, alpha = .05, n.sims = 1000, avg = FALSE, newdata = NULL, quasi.bayes = FALSE, keep.draws = FALSE, ...) } @@ -77,11 +77,11 @@ object, is then directly inputted into this function. } \examples{ -\dontrun{ data(nigeria) ## Define design parameters +\donttest{ set.seed(44) p <- 2/3 # probability of answering honestly in Forced Response Design @@ -103,8 +103,7 @@ rr.q1.pred.obj <- rr.q1.rrreg.predictor.pred <- predict(rr.q1.pred.obj, avg = TRUE, quasi.bayes = TRUE, - n.sims = 10000) - + n.sims = 1000) } } \references{ diff --git a/man/rr-package.Rd b/man/rr-package.Rd index 0bb3cef..1be3d2e 100644 --- a/man/rr-package.Rd +++ b/man/rr-package.Rd @@ -31,18 +31,18 @@ Date: \tab 2015-3-8\cr License: \tab GPL (>= 2)\cr } Blair, Graeme, Kosuke Imai and Yang-Yang Zhou. (2015) "Design and Analysis of the Randomized Response Technique." \emph{Journal of the American Statistical Association.} -Available at \url{http://graemeblair.com/papers/randresp.pdf}. +Available at \url{https://graemeblair.com/papers/randresp.pdf}. } \author{ Graeme Blair, Experiments in Governance and Politics, Columbia -University \email{graeme.blair@columbia.edu}, \url{http://graemeblair.com} +University \email{graeme.blair@gmail.com}, \url{https://graemeblair.com} -Kosuke Imai, Department of Politics, Princeton University -\email{kimai@princeton.edu}, \url{http://imai.princeton.edu} +Kosuke Imai, Departments of Government and Statistics, Harvard University +\email{kimai@harvard.edu}, \url{https://imai.fas.harvard.edu} -Yang-Yang Zhou, Department of Politics, Princeton University -\email{yz3@princeton.edu}, \url{http://yangyangzhou.com} +Yang-Yang Zhou, Department of Political Science, University of British Columbia +\email{yangyang.zhou@ubc.ca}, \url{https://www.yangyangzhou.com} -Maintainer: Graeme Blair +Maintainer: Graeme Blair } \keyword{package} diff --git a/man/rrreg.bayes.Rd b/man/rrreg.bayes.Rd index bb07f10..36f060f 100644 --- a/man/rrreg.bayes.Rd +++ b/man/rrreg.bayes.Rd @@ -142,12 +142,13 @@ mle.estimates <- rrreg(rr.q1 ~ cov.asset.index + cov.married + data = nigeria, p = p, p1 = p1, p0 = p0, design = "forced-known") + +\donttest{ library(MASS) draws <- mvrnorm(n = 3, mu = coef(mle.estimates), Sigma = vcov(mle.estimates) * 9) -\dontrun{ ## run three chains bayes.1 <- rrreg.bayes(rr.q1 ~ cov.asset.index + cov.married + I(cov.age/10) + I((cov.age/10)^2) + cov.education + cov.female, @@ -169,6 +170,7 @@ bayes.3 <- rrreg.bayes(rr.q1 ~ cov.asset.index + cov.married + bayes <- as.list(bayes.1, bayes.2, bayes.3) summary(bayes) + } } diff --git a/man/rrreg.predictor.Rd b/man/rrreg.predictor.Rd index 748db56..6b68b6f 100644 --- a/man/rrreg.predictor.Rd +++ b/man/rrreg.predictor.Rd @@ -140,7 +140,6 @@ p0 <- 1/6 # probability of forced 'no' ## Fit joint model of responses to an outcome regression of joining a civic ## group and the randomized response item of having a militant social connection -\dontrun{ rr.q1.pred.obj <- rrreg.predictor(civic ~ cov.asset.index + cov.married + I(cov.age/10) + I((cov.age/10)^2) + cov.education + cov.female @@ -149,7 +148,7 @@ rr.q1.pred.obj <- p = p, p1 = p1, p0 = p0, design = "forced-known") summary(rr.q1.pred.obj) -} + ## Replicates Table 4 in Blair, Imai, and Zhou (2014) } diff --git a/rr.Rproj b/rr.Rproj new file mode 100644 index 0000000..b1ded45 --- /dev/null +++ b/rr.Rproj @@ -0,0 +1,17 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: knitr +LaTeX: pdfLaTeX + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source diff --git a/src/subroutines.c b/src/subroutines.c index 06849b9..87fdd43 100644 --- a/src/subroutines.c +++ b/src/subroutines.c @@ -1,3 +1,4 @@ +#define USE_FC_LEN_T #include #include @@ -9,6 +10,10 @@ #include "vector.h" #include "rand.h" +#ifndef FCONE +# define FCONE +#endif + /* The Sweep operator */ void SWP( double **X, /* The Matrix to work on */ @@ -45,9 +50,9 @@ void dinv(double **X, for (i = 0, j = 0; j < size; j++) for (k = 0; k <= j; k++) pdInv[i++] = X[k][j]; - F77_CALL(dpptrf)("U", &size, pdInv, &errorM); + F77_CALL(dpptrf)("U", &size, pdInv, &errorM FCONE); if (!errorM) { - F77_CALL(dpptri)("U", &size, pdInv, &errorM); + F77_CALL(dpptri)("U", &size, pdInv, &errorM FCONE); if (errorM) { Rprintf("LAPACK dpptri failed, %d\n", errorM); error("Exiting from dinv().\n"); @@ -78,7 +83,7 @@ void dcholdc(double **X, int size, double **L) for (j = 0, i = 0; j < size; j++) for (k = 0; k <= j; k++) pdTemp[i++] = X[k][j]; - F77_CALL(dpptrf)("U", &size, pdTemp, &errorM); + F77_CALL(dpptrf)("U", &size, pdTemp, &errorM FCONE); if (errorM) { Rprintf("LAPACK dpptrf failed, %d\n", errorM); error("Exiting from dcholdc().\n"); diff --git a/tests/testthat/test-bayes-mixed.R b/tests/testthat/test-bayes-mixed.R index b877589..fc1104e 100644 --- a/tests/testthat/test-bayes-mixed.R +++ b/tests/testthat/test-bayes-mixed.R @@ -1,7 +1,5 @@ context("Tests Bayesian regression code (rrreg.bayes) with mixed effects") -rm(list=ls()) - ## Define design parameters p <- 2/3 # probability of answering honestly in Forced Response Design p1 <- 1/6 # probability of forced 'yes' diff --git a/tests/testthat/test-bayes.R b/tests/testthat/test-bayes.R index ee31a49..0a57157 100644 --- a/tests/testthat/test-bayes.R +++ b/tests/testthat/test-bayes.R @@ -1,7 +1,5 @@ context("Tests Bayesian regression code (rrreg.bayes)") -rm(list=ls()) - ## Define design parameters p <- 2/3 # probability of answering honestly in Forced Response Design p1 <- 1/6 # probability of forced 'yes' diff --git a/tests/testthat/test-power.R b/tests/testthat/test-power.R index 8141346..4eb0a4b 100644 --- a/tests/testthat/test-power.R +++ b/tests/testthat/test-power.R @@ -1,7 +1,5 @@ context("Tests power analysis code (power.rr.test)") -rm(list=ls()) - ####### FORCED DESIGN #################### ## Define design parameters diff --git a/tests/testthat/test-rrreg-predictor.R b/tests/testthat/test-rrreg-predictor.R index e43c6ca..0adf1a6 100644 --- a/tests/testthat/test-rrreg-predictor.R +++ b/tests/testthat/test-rrreg-predictor.R @@ -1,7 +1,5 @@ context("Tests regression code (rrreg.predictor)") -rm(list=ls()) - ####### FORCED DESIGN #################### ## Define design parameters diff --git a/tests/testthat/test-rrreg.R b/tests/testthat/test-rrreg.R index 4b541d5..0f838cb 100644 --- a/tests/testthat/test-rrreg.R +++ b/tests/testthat/test-rrreg.R @@ -1,7 +1,5 @@ context("Tests regression code (rrreg)") -rm(list=ls()) - ####### FORCED DESIGN #################### ## Define design parameters