-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_effect_size.R
55 lines (54 loc) · 1.79 KB
/
new_effect_size.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
new_effect_size <- function(x, y, global = T, area = 'World'){
if (str_detect(class(x), "raster|Raster")) {
cont.name <- c('Asia', 'North America', 'Europe', 'Africa', 'South America', 'Oceania')
if(global == F){
cont.value <- which(cont.name == area)
clipped.continent <- clamp(continents, lower = cont.value, upper = cont.value, useValues = F) / cont.value
x <- mask(x, clipped.continent)
y <- mask(y, clipped.continent)
}
x <- na.omit(values(x))
y <- na.omit(values(y))
}
# rank-sum test
p.value <- wilcox.test(x, y)$p.value
# all favorable pairs
P <- sum(unlist(1:length(x) %>% map(function(i) sum(x[i] > y))))
# all unfavorable pairs
N <- sum(unlist(1:length(x) %>% map(function(i) sum(x[i] < y))))
# all ties
E <- sum(unlist(1:length(x) %>% map(function(i) sum(x[i] == y))))
# total
Tot <- tryCatch(P + N + E,
warning = function(w) {
warning(w, "Coercing to numeric, results might be inaccurate")
as.numeric(P) + as.numeric(N) + as.numeric(E)
})
r = (P - N) / (Tot)
prob = P / Tot
fraction = 10^mean(y - x)
return(tibble(`p` = p.value,
`r` = r,
`P(X > Y)` = prob,
Area = area,
Fraction = fraction))
}
magnitude <- function(superiority){
x <- rep(NA, length(superiority))
for(i in 1:length(superiority)){
if(superiority[i] >= 0.92){
x[i] <- 'Huge'
} else if(superiority[i] >= 0.80){
x[i] <- 'Very large'
} else if(superiority[i] >= 0.71){
x[i] <- 'Large'
} else if(superiority[i] >= 0.64){
x[i] <- 'Medium'
} else if(superiority[i] >= 0.56){
x[i] <- 'Small'
} else if(superiority[i] < 0.56){
x[i] <- ('No difference')
}
}
return(x)
}