-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_examples.R
45 lines (33 loc) · 1.04 KB
/
stats_examples.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
library(stats)
numerator <- 10
denominator <- 100
rate <- numerator/denominator
confidence_interval <- binom.test(numerator,denominator)
confidence_interval <- binom.test(numerator, denominator, conf.level = 0.95)$conf.int
confidence_interval
# Example data
data <- c(0.1, 0.25, 0.08, 0.14) # Replace with your actual data
# Function to compute index of disparity
compute_id <- function(data) {
# Compute index of disparity (replace this with your own formula)
id <- sum(data) / length(data) # Example formula, replace with your own
return(id)
}
compute_id(data)
# Function to perform bootstrapping
bootstrap <- function(data, num_iter = 1000) {
ids <- numeric(num_iter)
for (i in 1:num_iter) {
# Resample data with replacement
resampled_data <- sample(data, replace = TRUE)
# Compute index of disparity for resampled data
ids[i] <- compute_id(resampled_data)
}
return(ids)
}
# Perform bootstrapping
bootstrap_ids <- bootstrap(data)
# Calculate standard error
se <- sd(bootstrap_ids)
# Print standard error
print(se)