Skip to content

phase_test() doesn't rank the phases correctly #16

@stephaniereinders

Description

@stephaniereinders

I forked bulletxtrctr to the CSAFE-ISU organization this afternoon.

The avgs data frame in phase_test() doesn't rank the phases from lowest to highest mean as expected. Intermediate calculations are not output by phase_test(), so I copied the first section of lines to a separate script.

# Make example data
set.seed(100)
land1 <- rep(1:6, each = 6)
land2 <- rep(1:6, times = 6)
score <- runif(n = 36)
sigma_0 <- NA

# The body of `phase_test()`
# data frame with structure land 1, land 2, score
  # returns estimate 1, estimate 2, test statistic (difference), sigma (of reference distribution),
  # and p-value
  if (is.numeric(sigma_0)) stopifnot(sigma_0 > 0) # only positive values for sigma_0 are allowed

  DNAME <- deparse(substitute(score))

 dframe <- data.frame(land1, land2, score)
 dframe <- dframe %>%
    arrange(land1, land2) %>% # provides row-first order (land2 is slower index)
    mutate(
      phase = get_phases(land1, land2)
    ) %>%
    arrange(land1, land2)
 n <- max(dframe$phase)
 avgs <- dframe %>% group_by(phase) %>%
    summarize(
      means = mean(score, na.rm = TRUE)
    ) %>% ungroup() %>%
    mutate(
      ordered = (1:n)[order(.data$means)]
    ) %>% arrange(means)
 dframe <- dframe %>% mutate(
    phase = avgs$ordered[.data$phase]
  )

# Make Table 1: avgs 
knitr::kable(avgs)

# Make Table 2: dframe summarized as means by group
temp <- dframe %>%
    group_by(phase) %>%
    summarize(means = mean(score))
knitr::kable(temp)

# Make Table 3: The first step in calculating the sigmas data frame is assigning the "in-phase". But the "in-phase" does not have the highest mean.
sigmas <- dframe |> mutate(inphase = .data$phase==n)
temp <- sigmas %>% group_by(inphase) %>% summarize(means = mean(score))
knitr::kable(temp)

Table 1. avgs. The highest rank is not assigned to the largest mean.

phase means ordered
4 0.3197486 1
6 0.4629385 3
5 0.5041292 2
1 0.5983320 4
2 0.6346167 6
3 0.6743031 5

Table 2. dframe means by phase. Phase 6 does not correspond to the largest phase mean.

phase means
1 0.5983320
2 0.6743031
3 0.6346167
4 0.3197486
5 0.4629385
6 0.5041292

Table 3. The in-phase has a lower average than the average of the off-phases

inphase means
FALSE 0.5379878
TRUE 0.5041292

Session Info

R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.7.4

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Chicago
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] bulletxtrctr_0.2.0.9000 testthat_3.2.3 dplyr_1.1.4

loaded via a namespace (and not attached):
[1] tidyselect_1.2.1 farver_2.1.2 S7_0.2.0
[4] fastmap_1.2.0 pracma_2.4.6 promises_1.5.0
[7] bulletcp_1.0.0 digest_0.6.37 mime_0.13
[10] lifecycle_1.0.4 x3ptools_0.0.4.9000 ellipsis_0.3.2
[13] magrittr_2.0.4 compiler_4.4.1 rlang_1.1.6
[16] tools_4.4.1 igraph_2.2.1 yaml_2.3.10
[19] knitr_1.50 htmlwidgets_1.6.4 pkgbuild_1.4.7
[22] curl_7.0.0 xml2_1.4.1 TTR_0.24.4
[25] RColorBrewer_1.1-3 pkgload_1.4.0 miniUI_0.1.2
[28] withr_3.0.2 purrr_1.2.0 imager_1.0.5
[31] desc_1.4.3 grid_4.4.1 rgl_1.3.24
[34] urlchecker_1.0.1 profvis_0.4.0 xts_0.14.1
[37] xtable_1.8-4 ggplot2_4.0.0.9000 scales_1.4.0
[40] MASS_7.3-65 readbitmap_0.1.5 cli_3.6.5
[43] mvtnorm_1.3-3 generics_0.1.4 remotes_2.5.0.9000
[46] otel_0.2.0 rstudioapi_0.17.1 tzdb_0.5.0
[49] sessioninfo_1.2.3 cachem_1.1.0 stringr_1.6.0
[52] assertthat_0.2.1 tiff_0.1-12 base64enc_0.1-3
[55] vctrs_0.6.5 devtools_2.4.5 jsonlite_2.0.0
[58] hms_1.1.4 jpeg_0.1-11 locfit_1.5-9.12
[61] tidyr_1.3.1 grooveFinder_0.0.1 glue_1.8.0
[64] stringi_1.8.7 gtable_0.3.6 later_1.4.4
[67] tibble_3.3.0 pillar_1.11.1 brio_1.1.5
[70] htmltools_0.5.8.1 R6_2.6.1 Rdpack_2.6.4
[73] rprojroot_2.0.4 bmp_0.3.1 evaluate_1.0.5
[76] shiny_1.11.1 lattice_0.22-7 readr_2.1.5
[79] rbibutils_2.3 png_0.1-8 backports_1.5.0
[82] memoise_2.0.1 broom_1.0.10 httpuv_1.6.16
[85] Rcpp_1.1.0 smoother_1.3 xfun_0.54
[88] fs_1.6.6 zoo_1.8-14 usethis_3.1.0
[91] pkgconfig_2.0.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions