-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsandbox.R
More file actions
122 lines (96 loc) · 2.38 KB
/
Copy pathsandbox.R
File metadata and controls
122 lines (96 loc) · 2.38 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# install.packages("ggquiver")
library(ggquiver)
library(tidyverse)
theme_set(theme_minimal())
# Quiver plots of mathematical functions
field <- expand.grid(x = seq(0, pi, pi / 12), y = seq(0, pi, pi / 12))
field |>
mutate(
u = cos(x),
v = sin(y)
) |>
ggplot(aes(x = x, y = y, u = u, v = v, color = factor(u * v))) +
geom_quiver(show.legend = FALSE)
# Removing automatic scaling
ggplot(seals, aes(
x = long,
y = lat,
u = delta_long,
v = delta_lat
)) +
geom_quiver(aes(color = delta_long + delta_lat),
show.legend = FALSE,
rescale = TRUE
) +
borders("state") +
theme_void()
field2 <- expand.grid(x = seq(-10, 10), y = seq(-10, 10))
field2 |>
mutate(
u = -y,
v = x
) |>
ggplot(aes(x = x, y = y, u = u, v = v, color = sqrt(u^2 + v^2))) +
geom_quiver(show.legend = FALSE, rescale = TRUE)
################
func <- \(r){
(r * sqrt(1 - (r / 2)^2)) + ((2 - r^2) * acos(r / 2)) - (pi / 2)
}
seq(0, 2, by = .001) |>
tibble(x = _) |>
mutate(
y = func(x)
) |>
ggplot() +
geom_line(aes(x = x, y = y))
uniroot(func, c(0, 2))$root
conf <- .95
al <- 1 - conf
df <- tibble(
order_stat_lower_bound = NA_real_,
order_stat_upper_bound = NA_real_
)
for (i in 1:n) {
qorderstat <- jth_order_stat_qf(cdf, i, n)
df[i, 5:6] <- qorderstat(c(al / 2, 1 - al / 2)) |> t()
}
ggplot(df, aes(theoretical_quantiles, order_stats)) +
geom_errorbar(
aes(ymin = order_stat_lower_bound, ymax = order_stat_upper_bound),
color = "gray40", alpha = .30
) +
geom_function(fun = ~.x, color = "red", linetype = "dashed") +
# geom_point(size = 1.5) +
geom_point(aes(fill = ps_of_order_stats), size = 1.5, shape = 21) +
scale_fill_gradientn(
colors = rainbow(10), limits = 0:1, labels = scales::percent_format()
) +
coord_equal() +
labs(
x = "Theoretical quantiles of N(0,1)",
y = "Observed quantiles = order statistics",
fill = "p"
) +
theme(
plot.caption = element_text(size = 6, color = "gray75")
# panel.grid.major = element_blank()
)
library(future)
library(purrr)
library(furrr)
library(progressr)
plan(multisession)
1:10 %>%
future_map(rnorm, n = 10, .options = furrr_options(seed = 123)) %>%
future_map_dbl(mean) |>
with_progress()
xs <- 1:25
with_progress({
p <- progressor(along = xs)
y <- lapply(xs, function(x) {
Sys.sleep(0.1)
p(sprintf("x=%g", x))
sqrt(x)
})
})
plan(sequential)