View testing.r
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ANOVA testing by group | |
data %>% | |
group_by(your_group) %>% | |
do(tidy(aov(y ~ factor(x), data = .))) %>% | |
select(your_group, p.value) | |
# CHISQUARE testing by group | |
data %>% | |
group_by(your_group) %>% | |
summarise(pvalue = chisq.test(x, y)$p.value) %>% |
View app.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#libraries | |
library(shiny) | |
library(ggplot2) | |
library(dplyr) | |
library(DT) | |
library(tableone) | |
# data | |
# mtcars[, c("cyl", "vs", "am", "gear", "carb")] <- lapply(mtcars[, c("cyl", "vs", "am", "gear", "carb")], factor) | |
# data1 |
View ggMeanMedian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggplot(${1:data = }, aes(${2:x = )}) + | |
geom_histogram(aes(y = ..density..), ${3:binwidth = }, colour = "black", fill = "white") + | |
geom_density(alpha = .2, fill = "#FF6666") + | |
geom_vline(aes(xintercept = mean(${4:}), color = "mean"), linetype = "dashed", size = 2) + | |
geom_vline(aes(xintercept = median(${5:}), color = "median"), linetype = "dashed", size = 2) + | |
scale_color_manual(name = "Dispersion", values = c(median = "blue", mean = "red")) |
View tbl_steele.r
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# try to do table function in base R | |
tbl_steele <- function(data, var, ...){ | |
require(descr) | |
require(htmlTable) | |
levels_logic <- lapply(data[, var], function(x) levels(x)) | |
levels_logic1 <- lapply(levels_logic, function(x) is.null(x)) # combine these statements in the future | |
if(sum(unlist(levels_logic1)) < length(var)){ | |
cat("Are all of your variables properly labelled?\n") |
View model_output.r
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model_output <- function(mod_obj){ | |
# libraries | |
require(geepack); require(tibble); require(dplyr) | |
xvar <- names(lm_object$model)[-1] | |
yvar <- names(lm_object$model)[1] # idky i need this but just in case | |
data <- lm_object$data | |
# xvar levels | |
xvar_levels <- sapply(data[, xvar], levels) | |
xvar_levels_unlist <- unlist(lapply(seq_along(xvar_levels), |
View html_table.r
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quite a few requirements so read closely | |
# - variable must filter out NAs | |
# - variable must be a factor | |
# - variable must have factor labels (i think) | |
# - must be slightly comfortable with dplyr | |
# FUNCTION | |
tbl_steele <- function(data, names){ | |
require(htmlTable) | |
a <- lapply(data, function(x) freq(x, plot = F)) |
View list_levels.r
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# place list levels in object | |
list_levels <- | |
mtcars %>% select(vs, gear) %>% | |
transmute(vs_fctr = factor(vs, labels = c("0. Zero", "1. One")), | |
gear_fctr = factor(gear, labels = c("3. Three", "4. Four", "5. Five"))) %>% | |
sapply(levels) # sapply extracts unique levels from all variables | |
# i still don't understand this code but it works... | |
lapply(seq_along(list_levels), | |
function(i) paste(names(list_levels)[[i]], list_levels[[i]], sep = "")) %>% |