Skip to content

Commit

Permalink
Neal's recommendation about double booleans; also added an edge case …
Browse files Browse the repository at this point in the history
…check to sd and sd_between being out of sync.
  • Loading branch information
aaronrudkin committed Jan 22, 2018
1 parent 87c754f commit 6aa9015
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions R/draw_normal_icc.R
Expand Up @@ -80,7 +80,7 @@ draw_normal_icc = function(mean = 0,

# Sanity check ICC
if(is.null(ICC)) {
if(is.null(sd) | is.null(sd_between)) {
if(is.null(sd) || is.null(sd_between)) {
stop("If `ICC` is not provided, both `sd` and `sd_between` must be provided.")
} else {
implied_ICC = sd_between^2 / (sd_between^2 + sd^2)
Expand All @@ -89,7 +89,7 @@ draw_normal_icc = function(mean = 0,
} else {
# Fill in a default value if only ICC is specified; sd within-cluster = 1
# i.e. each cluster is unit variance.
if(is.null(sd) & is.null(sd_between)) {
if(is.null(sd) && is.null(sd_between)) {
sd = 1
}

Expand Down Expand Up @@ -179,6 +179,10 @@ draw_normal_icc = function(mean = 0,
sd_between = sqrt( (ICC * sd^2) / (1 - ICC) )
}

if(length(sd) != length(sd_between)) {
stop("Lengths of `sd` and `sd_between` must be identical.")
}

# Cluster means are either the same or individually supplied
if(length(mean) == 1) {
cluster_mean = rep(mean, number_of_clusters)
Expand Down

0 comments on commit 6aa9015

Please sign in to comment.