PolyaUrn: Randomized Pólya urn procedure

View source: R/groupRAR_functions.R

PolyaUrnR Documentation

Randomized Pólya urn procedure

Description

Simulating the randomized Pólya urn procedure (number of arms \ge 2) with two-sided hypothesis testing in a clinical trial context.

Usage

PolyaUrn(k, p, ssn, Y0 = NULL, nsim = 2000, alpha = 0.05, test.fun = NULL,
         typeI = FALSE, seed = NULL)

Arguments

k

A positive integer. The number of treatment groups in the trial (k \ge 2).

p

A vector of length k with values between 0 and 1. The true success rates of the treatments, used to generate data for the simulations.

ssn

A positive integer. The total number of participants in each simulated trial.

Y0

A vector of length k giving the initial urn composition (number of balls of each treatment type). For instance, if Y0 = c(1, 1, 1), the first patient is assigned to each treatment with probability Y0 / sum(Y0). If Y0 is NULL (default), it is set to a vector of k ones.

nsim

A positive integer. The number of simulated trials, with a default value of 2000.

alpha

A number between 0 and 1. The significance level of the two-sided test, with a default value of 0.05.

test.fun

An optional function function(outcome, assignment) that returns the p-value of a test for one simulated trial, where outcome holds the observed responses and assignment the treatment labels (integers 1 to k); missing responses are removed first. The null hypothesis is rejected when the p-value is at most alpha. The default NULL uses the built-in two-sided tests: the t-test for two arms and the Wald chi-squared test of equal means for more than two arms (for binary responses, if some arms have no variability, the variances are computed from (S_k + 1)/(n_k + 2) as in Agresti and Caffo, 2000).

typeI

Logical. If TRUE, the simulation is repeated under the null hypothesis, with every arm's success rate set to the average of p, and the rejection rate is reported as type I error. The default is FALSE.

seed

An optional integer passed to set.seed before simulating, so that the results can be reproduced. The default NULL leaves the random number generator unchanged.

Details

The randomized Pólya urn (RPU) procedure can be described as follows. An urn initially contains at least one ball of each of the K treatment types. A ball is drawn from the urn with replacement. If a type i ball is drawn, i=1, \ldots, K, then treatment i is assigned to the next patient. If the response is a success, a ball of type i is added to the urn. Otherwise the urn remains unchanged.

Value

An object of class "grouprar", a list that is printed as a short summary (see print.grouprar), with the following elements.

method

The name of the procedure.

sample size

The total sample size.

parameter

The true success rates used in the simulations, named pA, pB, ...

propotion

The mean allocation proportion of each arm over the simulations, named treatment A, treatment B, ...

sd of propotion

The standard deviation of the allocation proportion of each arm over the simulations.

failure rate

The mean failure rate over the simulations.

sd of failure rate

The standard deviation of the failure rate (or mean response) over the simulations.

power

The proportion of simulated trials that reject the null hypothesis of equal success rates. Simulations in which the test cannot be computed are dropped.

data: failureRate

The failure rate (or mean response) of each simulated trial.

data: test

The test decision of each simulated trial (1 = reject).

data: assignment

The treatment assignments of the last simulated trial.

data: propotion

A data frame with the allocation proportions of each simulated trial.

data: allocation

An nsim by ssn matrix with the treatment assignments of every simulated trial.

type I error

Only if typeI = TRUE. The rejection rate under the null hypothesis.

The randomized Pólya urn tends to concentrate on one arm, so some arms can end with very few patients. The asymptotic tests are then far from their nominal level (the rejection rate under the null hypothesis can be well above alpha, especially for K \ge 3), and trials in which an arm has no patients give no test. Use typeI = TRUE to check the type I error.

References

Durham, S. D., Flournoy, N. and Li, W. (1998). A sequential design for maximizing the probability of a favourable response. Canadian Journal of Statistics, 26(3), 479-495. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2307/3315771")}

Examples

## a simple use
Polya.res <- PolyaUrn(k = 3, p = c(0.6, 0.7, 0.6), ssn = 200, Y0 = NULL,
                      nsim = 100, alpha = 0.05)

## view the output
Polya.res

  ## view all simulation settings
  Polya.res[["method"]]
  Polya.res[["parameter"]]

  ## view the simulation results
  Polya.res[["propotion"]]
  Polya.res[["failure rate"]]
  Polya.res[["power"]]
  Polya.res[["data: assignment"]]
  

grouprar documentation built on Oct. 9, 2026, 9:07 a.m.

Related to PolyaUrn in grouprar...