@@ -171,4 +171,145 @@ withr::with_seed(1234, {
171171 do.call(rbind , args = _)
172172})
173173
174+ withr :: with_seed(1234 , {
175+ cli :: cli_h1(" Power simulation for Archimedian spirals differing in variance" )
176+
177+ powers_n <- purrr :: map(Ns , \(N ) {
178+ cli :: cli_alert_info(" Running power simulation for n = {N} ..." )
179+ pvalues <- purrr :: map(
180+ 1 : R ,
181+ purrr :: in_parallel(
182+ \(r ) {
183+ archspirals1 <- phutil :: as_persistence_set(lapply(
184+ seq(N ),
185+ function (i ) {
186+ S1 <- tdaunif :: sample_arch_spiral(
187+ n = 120L ,
188+ arms = 2L ,
189+ ar = 1 ,
190+ sd = 0.05
191+ )
192+ phutil :: as_persistence(TDA :: ripsDiag(
193+ S1 ,
194+ maxdimension = 2 ,
195+ maxscale = 6
196+ ))
197+ }
198+ ))
199+
200+ archspirals2 <- phutil :: as_persistence_set(lapply(
201+ seq(N ),
202+ function (i ) {
203+ S2 <- tdaunif :: sample_arch_spiral(
204+ n = 60L ,
205+ arms = 2L ,
206+ ar = 1 ,
207+ sd = 0.05
208+ )
209+ phutil :: as_persistence(TDA :: ripsDiag(
210+ S2 ,
211+ maxdimension = 2 ,
212+ maxscale = 6
213+ ))
214+ }
215+ ))
216+
217+ list (
218+ mean_variance_tippett = inphr :: two_sample_test(
219+ archspirals1 ,
220+ archspirals2 ,
221+ B = B ,
222+ stat_functions = list (flipr :: stat_t_ip , flipr :: stat_f_ip ),
223+ npc = " tippett"
224+ ),
225+ mean_variance_fisher = inphr :: two_sample_test(
226+ archspirals1 ,
227+ archspirals2 ,
228+ B = B ,
229+ stat_functions = list (flipr :: stat_t_ip , flipr :: stat_f_ip ),
230+ npc = " fisher"
231+ ),
232+ mean_only = inphr :: two_sample_test(
233+ archspirals1 ,
234+ archspirals2 ,
235+ B = B ,
236+ stat_functions = list (flipr :: stat_t_ip )
237+ ),
238+ variance_only = inphr :: two_sample_test(
239+ archspirals1 ,
240+ archspirals2 ,
241+ B = B ,
242+ stat_functions = list (flipr :: stat_f_ip )
243+ )
244+ )
245+ },
246+ B = B ,
247+ R = R ,
248+ N = N
249+ )
250+ ) | >
251+ purrr :: list_transpose() | >
252+ purrr :: map_dbl(\(p ) mean(p < = alpha ))
253+ }) | >
254+ do.call(rbind , args = _)
255+ })
256+
174257mirai :: daemons(0 )
258+
259+ inference <- colnames(powers_variance )
260+
261+ tibble :: tibble(
262+ N = rep(Ns , times = 4L ),
263+ inference = rep(inference , each = length(Ns )),
264+ power_variance = c(powers_variance ),
265+ power_mean = c(powers_mean ),
266+ power_n = c(powers_n )
267+ ) | >
268+ tidyr :: pivot_longer(
269+ - c(N , inference ),
270+ names_to = c(" .value" , " type" ),
271+ names_pattern = " (.*)_(variance|mean|n)"
272+ ) | >
273+ dplyr :: mutate(
274+ type = factor (
275+ type ,
276+ levels = c(" variance" , " mean" , " n" ),
277+ labels = c(
278+ " Differences in variance" ,
279+ " Differences in mean" ,
280+ " Differences in sample size"
281+ )
282+ ),
283+ inference = factor (
284+ inference ,
285+ levels = c(
286+ " mean_variance_tippett" ,
287+ " mean_variance_fisher" ,
288+ " mean_only" ,
289+ " variance_only"
290+ ),
291+ labels = c(" Tippett" , " Fisher" , " Mean only" , " Variance only" )
292+ )
293+ ) | >
294+ ggplot(aes(x = N , y = power , color = inference )) +
295+ geom_line() +
296+ geom_point() +
297+ labs(
298+ x = " Sample size (n)" ,
299+ y = " Power" ,
300+ title = " Power of two-sample tests for Archimedian spirals"
301+ ) +
302+ facet_wrap(vars(type )) +
303+ theme_bw()
304+
305+ save(
306+ alpha ,
307+ inference ,
308+ Ns ,
309+ powers_mean ,
310+ powers_variance ,
311+ powers_n ,
312+ R ,
313+ B ,
314+ file = " data-raw/power.RData"
315+ )
0 commit comments