-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.R
71 lines (64 loc) · 1.58 KB
/
temp.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#' is_systematic function
#'
#'
#' @param DT data table to determine systemicity
#' @importFrom magrittr %>%
#' @importFrom dplyr group_by
#' @importFrom dplyr summarise
#' @importFrom dplyr group_by
#'
is_systematic <- function(DT) {
return(
DT %>%
group_by(part_id) %>%
summarise(split_acros_n_groups = length(unique(group_perm))) %>%
subset(split_acros_n_groups > 1) %>%
{nrow(.) == 0}
)
}
#'
#' # events <- c(1,0,0,1,1)
#' # groups <- c(1,2,1,2,1)
#' #
#' # system.time(haha <- tibble(event = events, group = groups) %>%
#' # mutate(all_mean = sum(event) / nrow(.)) %>%
#' # group_by(group) %>%
#' # summarise(
#' # gp_mean = sum(event) / n(),
#' # all_mean = unique(all_mean)
#' # ) %>%
#' # ungroup() %>%
#' # summarise(hehe = sum((gp_mean - all_mean)**2)) %>%
#' # pull())
#' #
#' # system.time(perm_test_statistic(events, groups))
#' #
#' # tapply(events, groups, mean)
#' # mean(events)
#'
#' # library(rstudioapi)
# setwd(dirname(rstudioapi::getSourceEditorContext()$path))
#
# library(readr)
#
# DF <- read_csv("data.csv") %>%
# select(-any_of(c("...1", "X"))) %>%
# mutate(across(c(everything(), -event), factor)) %>%
# mutate()
#
# group = "group"
# id_col_name = "part_id"
# event_col_name = "event"
#
# test_p <- perm_test(
# DF,
# group_col_name = group_col_name,
# idname = id_col_name,
# eventname = event_col_name,
# parallel = FALSE,
# ntrials=1000,
# ran_seed = 301031,
# systematic = TRUE
# )
#
# print(test_p)