<!-- Generated by pkgdown: do not edit by hand -->
<!DOCTYPE html>
<html>
  <head>
  <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Power Analysis for Randomized Response — power.rr.test • rr</title>

<!-- jquery -->
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha384-nrOSfDHtoPMzJHjVTdCopGqIqeYETSXhZDFyniQ8ZHcVy08QesyHcnOUpMpqnmWq" crossorigin="anonymous"></script>
<!-- Bootstrap -->

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<!-- Font Awesome icons -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">


<!-- pkgdown -->
<link href="../pkgdown.css" rel="stylesheet">
<script src="../jquery.sticky-kit.min.js"></script>
<script src="../pkgdown.js"></script>
  
  
<!-- mathjax -->
<script src='https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>

<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->


  </head>

  <body>
    <div class="container template-reference-topic">
      <header>
      <div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="../index.html">rr</a>
    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li>
  <a href="../reference/">Reference</a>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
    Packages
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
    <li>
      <a href="http://endorse.sensitivequestions.org">Endorsement experiments</a>
    </li>
    <li>
      <a href="http://list.sensitivequestions.org">List experiments</a>
    </li>
    <li>
      <a href="http://rr.sensitivequestions.org">Randomized response technique</a>
    </li>
  </ul>
</li>
<li>
  <a href="http://sensitivequestions.org">Sensitive Questions home</a>
</li>
      </ul>
      
      <ul class="nav navbar-nav navbar-right">
        
      </ul>
    </div><!--/.nav-collapse -->
  </div><!--/.container -->
</div><!--/.navbar -->

      
      </header>

      <div class="row">
  <div class="col-md-9 contents">
    <div class="page-header">
    <h1>Power Analysis for Randomized Response</h1>
    </div>

    
    <p><code>power.rr.test</code> is used to conduct power analysis for randomized
response survey designs.</p>
    

    <pre class="usage"><span class='fu'>power.rr.test</span>(<span class='no'>p</span>, <span class='no'>p0</span>, <span class='no'>p1</span>, <span class='no'>q</span>, <span class='no'>design</span>, <span class='kw'>n</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='no'>r</span>, <span class='no'>presp</span>, <span class='kw'>presp.null</span> <span class='kw'>=</span>
<span class='kw'>NULL</span>, <span class='no'>sig.level</span>, <span class='no'>prespT</span>, <span class='no'>prespC</span>, <span class='kw'>prespT.null</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='no'>prespC.null</span>, <span class='kw'>power</span> <span class='kw'>=</span>
<span class='kw'>NULL</span>, <span class='kw'>type</span> <span class='kw'>=</span> <span class='fu'>c</span>(<span class='st'>"one.sample"</span>, <span class='st'>"two.sample"</span>), <span class='kw'>alternative</span> <span class='kw'>=</span> <span class='fu'>c</span>(<span class='st'>"one.sided"</span>,
<span class='st'>"two.sided"</span>), <span class='kw'>solve.tolerance</span> <span class='kw'>=</span> <span class='no'>.Machine</span>$<span class='no'>double.eps</span>)</pre>
    
    <h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a> Arguments</h2>
    <table class="ref-arguments">
    <colgroup><col class="name" /><col class="desc" /></colgroup>
    <tr>
      <th>p</th>
      <td><p>The probability of receiving the sensitive question (Mirrored
Question Design, Unrelated Question Design); the probability of answering
truthfully (Forced Response Design); the probability of selecting a red card
from the 'yes' stack (Disguised Response Design).</p></td>
    </tr>
    <tr>
      <th>p0</th>
      <td><p>The probability of forced 'no' (Forced Response Design).</p></td>
    </tr>
    <tr>
      <th>p1</th>
      <td><p>The probability of forced 'yes' (Forced Response Design).</p></td>
    </tr>
    <tr>
      <th>q</th>
      <td><p>The probability of answering 'yes' to the unrelated question, which
is assumed to be independent of covariates (Unrelated Question Design).</p></td>
    </tr>
    <tr>
      <th>design</th>
      <td><p>Call of design (including modified designs) used:
"forced-known", "mirrored", "disguised", "unrelated-known",
"forced-unknown", and "unrelated-unknown".</p></td>
    </tr>
    <tr>
      <th>n</th>
      <td><p>Number of observations. Exactly one of 'n' or 'power' must be NULL.</p></td>
    </tr>
    <tr>
      <th>r</th>
      <td><p>For the modified designs only (i.e. "forced-unknown" for Forced
Response with Unknown Probability and "unrelated-unknown" for Unrelated
Question with Unknown Probability), <code>r</code> is the proportion of
respondents allocated to the first group, which is the group that is
directed to answer the sensitive question truthfully with probability
<code>p</code> as opposed to the second group which is directed to answer the
sensitive question truthfully with probability <code>1-p</code>.</p></td>
    </tr>
    <tr>
      <th>presp</th>
      <td><p>For a one sample test, the probability of possessing the
sensitive trait under the alternative hypothesis.</p></td>
    </tr>
    <tr>
      <th>presp.null</th>
      <td><p>For a one sample test, the probability of possessing the
sensitive trait under the null hypothesis. The default is <code>NULL</code>
meaning zero probability of possessing the sensitive trait.</p></td>
    </tr>
    <tr>
      <th>sig.level</th>
      <td><p>Significance level (Type I error probability).</p></td>
    </tr>
    <tr>
      <th>prespT</th>
      <td><p>For a two sample test, the probability of the treated group
possessing the sensitive trait under the alternative hypothesis.</p></td>
    </tr>
    <tr>
      <th>prespC</th>
      <td><p>For a two sample test, the probability of the control group
possessing the sensitive trait under the alternative hypothesis.</p></td>
    </tr>
    <tr>
      <th>prespT.null</th>
      <td><p>For a two sample test, the probability of the treated
group possessing the sensitive trait under the null hypothesis. The default
is <code>NULL</code> meaning there is no difference between the treated and
control groups, specifically that <code>prespT.null</code> is the same as
<code>prespC.null</code>, the probability of the control group possessing the
sensitive trait under the null hypothesis.</p></td>
    </tr>
    <tr>
      <th>prespC.null</th>
      <td><p>For a two sample test, the probability of the control
group possessing the sensitive trait under the null hypothesis.</p></td>
    </tr>
    <tr>
      <th>power</th>
      <td><p>Power of test (Type II error probability). Exactly one of 'n'
or 'power' must be NULL.</p></td>
    </tr>
    <tr>
      <th>type</th>
      <td><p>One or two sample test. For a two sample test, the alternative
and null hypotheses refer to the difference between the two samples of the
probabilities of possessing the sensitive trait.</p></td>
    </tr>
    <tr>
      <th>alternative</th>
      <td><p>One or two sided test.</p></td>
    </tr>
    <tr>
      <th>solve.tolerance</th>
      <td><p>When standard errors are calculated, this option
specifies the tolerance of the matrix inversion operation solve.</p></td>
    </tr>
    </table>
    
    <h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>

    <p><code>power.rr.test</code> contains the following components (the
inclusion of some components such as the design parameters are dependent
upon the design used):</p>
<dt>n</dt><dd><p>Point estimates for the effects of covariates on the randomized
response item.</p></dd> <dt>r</dt><dd><p>Standard errors for estimates of the effects of
covariates on the randomized response item.</p></dd> <dt>presp</dt><dd><p>For a one sample
test, the probability of possessing the sensitive trait under the
alternative hypothesis.  For a two sample test, the difference between the
probabilities of possessing the sensitive trait for the treated and control
groups under the alternative hypothesis.</p></dd> <dt>presp.null</dt><dd><p>For a one sample
test, the probability of possessing the sensitive trait under the null
hypothesis. For a two sample test, the difference between the probabilities
of possessing the sensitive trait for the treated and control groups under
the null hypothesis.</p></dd> <dt>sig.level</dt><dd><p>Significance level (Type I error
probability).</p></dd> <dt>power</dt><dd><p>Power of test (Type II error probability).</p></dd>
<dt>type</dt><dd><p>One or two sample test.</p></dd> <dt>alternative</dt><dd><p>One or two sided
test.</p></dd>

    
    <h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>

    <p>This function allows users to conduct power analysis for randomized response
survey designs, both for the standard designs ("forced-known", "mirrored",
"disguised", "unrelated-known") and modified designs ("forced-unknown", and
"unrelated -unknown").</p>
    
    <h2 class="hasAnchor" id="references"><a class="anchor" href="#references"></a>References</h2>

    <p>Blair, Graeme, Kosuke Imai and Yang-Yang Zhou. (2015) "Design
and Analysis of the Randomized Response Technique."  <em>Journal of the 
American Statistical Association.</em>
Available at <a href='http://graemeblair.com/papers/randresp.pdf'>http://graemeblair.com/papers/randresp.pdf</a>.</p>
    

    <h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
    <pre class="examples"><div class='input'>

<span class='co'>## Calculate the power to detect a sensitive item proportion of .2</span>
<span class='co'>## with the forced design with known probabilities of 2/3 in truth-telling group,</span>
<span class='co'>## 1/6 forced to say "yes" and 1/6 forced to say "no" and sample size of 200.</span>

<span class='fu'>power.rr.test</span>(<span class='kw'>p</span> <span class='kw'>=</span> <span class='fl'>2</span>/<span class='fl'>3</span>, <span class='kw'>p1</span> <span class='kw'>=</span> <span class='fl'>1</span>/<span class='fl'>6</span>, <span class='kw'>p0</span> <span class='kw'>=</span> <span class='fl'>1</span>/<span class='fl'>6</span>, <span class='kw'>n</span> <span class='kw'>=</span> <span class='fl'>200</span>,
             <span class='kw'>presp</span> <span class='kw'>=</span> <span class='fl'>.2</span>, <span class='kw'>presp.null</span> <span class='kw'>=</span> <span class='fl'>0</span>,
             <span class='kw'>design</span> <span class='kw'>=</span> <span class='st'>"forced-known"</span>, <span class='kw'>sig.level</span> <span class='kw'>=</span> <span class='fl'>.01</span>,
             <span class='kw'>type</span> <span class='kw'>=</span> <span class='st'>"one.sample"</span>, <span class='kw'>alternative</span> <span class='kw'>=</span> <span class='st'>"one.sided"</span>)</div><div class='output co'>#&gt; $design
#&gt; [1] "forced-known"
#&gt; 
#&gt; $n
#&gt; [1] 200
#&gt; 
#&gt; $r
#&gt; NULL
#&gt; 
#&gt; $presp
#&gt; [1] 0.2
#&gt; 
#&gt; $presp.null
#&gt; [1] 0
#&gt; 
#&gt; $sig.level
#&gt; [1] 0.01
#&gt; 
#&gt; $power
#&gt; [1] 0.9868872
#&gt; 
#&gt; $type
#&gt; [1] "one.sample"
#&gt; 
#&gt; $alternative
#&gt; [1] "one.sided"
#&gt; </div><div class='input'>				       
</div><span class='co'># NOT RUN {</span>
<span class='co'>## Find power varying the number of respondents from 250 to 2500 and </span>
<span class='co'>## the population proportion of respondents possessing the sensitive </span>
<span class='co'>## trait from 0 to .15</span>

<span class='no'>presp.seq</span> <span class='kw'>&lt;-</span> <span class='fu'>seq</span>(<span class='kw'>from</span> <span class='kw'>=</span> <span class='fl'>0</span>, <span class='kw'>to</span> <span class='kw'>=</span> <span class='fl'>.15</span>, <span class='kw'>by</span> <span class='kw'>=</span> <span class='fl'>.0025</span>)
<span class='no'>n.seq</span> <span class='kw'>&lt;-</span> <span class='fu'>c</span>(<span class='fl'>250</span>, <span class='fl'>500</span>, <span class='fl'>1000</span>, <span class='fl'>2000</span>, <span class='fl'>2500</span>)
<span class='no'>power</span> <span class='kw'>&lt;-</span> <span class='fu'>list</span>()
<span class='kw'>for</span>(<span class='no'>n</span> <span class='kw'>in</span> <span class='no'>n.seq</span>) {
    <span class='no'>power</span><span class='kw'>[[</span><span class='no'>n</span>]] <span class='kw'>&lt;-</span> <span class='fu'>rep</span>(<span class='fl'>NA</span>, <span class='fu'>length</span>(<span class='no'>presp.seq</span>))
    <span class='kw'>for</span>(<span class='no'>i</span> <span class='kw'>in</span> <span class='fl'>1</span>:<span class='fu'>length</span>(<span class='no'>presp.seq</span>))
        <span class='no'>power</span><span class='kw'>[[</span><span class='no'>n</span>]][<span class='no'>i</span>] <span class='kw'>&lt;-</span> <span class='fu'>power.rr.test</span>(<span class='kw'>p</span> <span class='kw'>=</span> <span class='fl'>2</span>/<span class='fl'>3</span>, <span class='kw'>p1</span> <span class='kw'>=</span> <span class='fl'>1</span>/<span class='fl'>6</span>, <span class='kw'>p0</span> <span class='kw'>=</span> <span class='fl'>1</span>/<span class='fl'>6</span>, <span class='kw'>n</span> <span class='kw'>=</span> <span class='no'>n</span>,
                                       <span class='kw'>presp</span> <span class='kw'>=</span> <span class='no'>presp.seq</span>[<span class='no'>i</span>], <span class='kw'>presp.null</span> <span class='kw'>=</span> <span class='fl'>0</span>,
                                       <span class='kw'>design</span> <span class='kw'>=</span> <span class='st'>"forced-known"</span>, <span class='kw'>sig.level</span> <span class='kw'>=</span> <span class='fl'>.01</span>,
                                       <span class='kw'>type</span> <span class='kw'>=</span> <span class='st'>"one.sample"</span>,
                                       <span class='kw'>alternative</span> <span class='kw'>=</span> <span class='st'>"one.sided"</span>)$<span class='no'>power</span>
    }

<span class='co'>## Replicates the results for Figure 2 in Blair, Imai, and Zhou (2014)</span>
<span class='co'># }</span><div class='input'>
</div></pre>
  </div>
  <div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
    <h2>Contents</h2>
    <ul class="nav nav-pills nav-stacked">
      <li><a href="#arguments">Arguments</a></li>
      
      <li><a href="#value">Value</a></li>

      <li><a href="#details">Details</a></li>

      <li><a href="#references">References</a></li>
      
      <li><a href="#examples">Examples</a></li>
    </ul>

  </div>
</div>

      <footer>
      <div class="copyright">
  <p>Developed by Graeme Blair, Yang-Yang Zhou, Kosuke Imai.</p>
</div>

<div class="pkgdown">
  <p>Site built with <a href="http://hadley.github.io/pkgdown/">pkgdown</a>.</p>
</div>

      </footer>
   </div>

  </body>
</html>
