R/method-permute.r

Defines functions null_permute

Documented in null_permute

# Multivariate independence --------------------------------------------------


#' Generate null data by permuting a variable.
#'
#' Null hypothesis: variable is independent of others
#'
#' @param var name of variable to permute
#' @return a function that given \code{data} generates a null data set.
#'   For use with \code{\link{lineup}} or \code{\link{rorschach}}
#' @export
#' @seealso null_lm, null_dist
#' @examples
#' data(mtcars)
#' library(ggplot2)
#' ggplot(data=rorschach(method=null_permute("mpg"), n = 3, true=mtcars)) +
#' geom_boxplot(aes(x=factor(cyl), y=mpg, fill=factor(cyl))) +facet_grid(.~.sample) +
#' theme(legend.position="none", aspect.ratio=1)
null_permute <- function(var) {
    function(df) {
        df[[var]] <- sample(df[[var]])
        df
    }
}

Try the nullabor package in your browser

Any scripts or data that you put into this service are public.

nullabor documentation built on Feb. 26, 2020, 1:07 a.m.