зеркало из https://github.com/microsoft/wpa.git
docs: update roxygen
- Add comments to examples - Explicit namespacing for `stats::filter()` and `dplyr::filter()` - to avoid conflict warning messages upon package load - Make explicit the method used
This commit is contained in:
Родитель
bd74539d0b
Коммит
3890e21c99
23
R/p_test.R
23
R/p_test.R
|
@ -16,9 +16,13 @@
|
|||
#' @param paired Specify whether the dataset is paired or not. Defaults to TRUE.
|
||||
#'
|
||||
#' @import dplyr
|
||||
#' @import stats
|
||||
#'
|
||||
#' @details
|
||||
#' This function is a wrapper around `wilcox.test()` from {stats}.
|
||||
#'
|
||||
#' @examples
|
||||
#' # Simulate a binary variable X
|
||||
#' # Returns a single p-value
|
||||
#' sq_data %>%
|
||||
#' mutate(X = ifelse(Email_hours > 6, 1, 0)) %>%
|
||||
#' p_test(outcome = "X", behavior = "External_network_size")
|
||||
|
@ -26,19 +30,20 @@
|
|||
|
||||
|
||||
|
||||
p_test <- function(data,
|
||||
outcome,
|
||||
p_test <- function(data,
|
||||
outcome,
|
||||
behavior,
|
||||
paired = FALSE){
|
||||
train <- data %>%
|
||||
train <- data %>%
|
||||
filter(!!sym(outcome) == 1 | !!sym(outcome) == 0) %>%
|
||||
select(!!sym(outcome), !!sym(behavior)) %>%
|
||||
mutate(outcome = as.character(!!sym(outcome))) %>%
|
||||
mutate(outcome = as.factor(!!sym(outcome)))
|
||||
|
||||
pos <- train %>% filter(outcome == 1, na.rm=TRUE) %>% select(behavior)
|
||||
neg <- train %>% filter(outcome == 0, na.rm=TRUE) %>% select(behavior)
|
||||
|
||||
|
||||
pos <- train %>% filter(outcome == 1, na.rm=TRUE) %>% select(behavior)
|
||||
neg <- train %>% filter(outcome == 0, na.rm=TRUE) %>% select(behavior)
|
||||
|
||||
s <- stats::wilcox.test(unlist(pos), unlist(neg), paired = paired)
|
||||
|
||||
return(s$p.value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
\alias{p_test}
|
||||
\title{Calculate the p-value of the null hypothesis that two outcomes are from the same dataset}
|
||||
\usage{
|
||||
p_test(data, outcome, behavior)
|
||||
p_test(data, outcome, behavior, paired = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{data}{A Person Query dataset in the form of a data frame.}
|
||||
|
@ -13,8 +13,20 @@ p_test(data, outcome, behavior)
|
|||
the values 1 or 0. Used to group the two distributions.}
|
||||
|
||||
\item{behavior}{A character vector specifying the column to be used as the behavior to test.}
|
||||
|
||||
\item{paired}{Specify whether the dataset is paired or not. Defaults to TRUE.}
|
||||
}
|
||||
\description{
|
||||
Specify an outcome variable and return p-test outputs.
|
||||
All numeric variables in the dataset are used as predictor variables.
|
||||
}
|
||||
\details{
|
||||
This function is a wrapper around \code{wilcox.test()} from {stats}.
|
||||
}
|
||||
\examples{
|
||||
# Simulate a binary variable X
|
||||
# Returns a single p-value
|
||||
sq_data \%>\%
|
||||
mutate(X = ifelse(Email_hours > 6, 1, 0)) \%>\%
|
||||
p_test(outcome = "X", behavior = "External_network_size")
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче