# Troubleshooting

# Installation

If you encounter any issues with installation, try the following script to see if it resolves your issue, as this will also install the other packages that are necessary for `concurve` to function.

    install.packages("concurve", dep = TRUE)

If that doesn’t work, please try installing, and resinstalling `R`, and then installing the package again.

You can also try installing the developer version with

    library(devtools)
    install_github("zadrafi/concurve")

# Unable to Plot Function

If you encounter an error such as “Error: ‘data’ must be a data frame from ‘concurve’.”, it is very likely that you are not providing `ggcurve()` the correct argument. If you used a function like `curve_gen()` to generate intervals and saved it to an object called ‘object’, you need to provide `ggcurve()` a data argument such as `object[[1]]` rather than `object` or `object[1]`. This is because although you saved your results to something called `object`, you ended up with a list with multiple components used for different purposes, usually with the first part of the list being the most commonly used part.

We can actually see these components one by one. Let’s generate some example data.

    library(concurve)
    set.seed(1031)
    GroupA <- rnorm(500)
    GroupB <- rnorm(500)
    RandomData <- data.frame(GroupA, GroupB)
    object <- curve_mean(GroupA, GroupB,
      data = RandomData, method = "default"
    )

As stated, the first part of the list `object[[1]]` contains what we usually want (I’m restricting to the first 5 results using the `head()` function so that we don’t print a giant list with 1000 rows.)

    head(object[[1]], 5)
    #>   lower.limit upper.limit intrvl.width intrvl.level     cdf pvalue       svalue
    #> 1  -0.1125581  -0.1125581 0.000000e+00        0e+00 0.50000 1.0000 0.0000000000
    #> 2  -0.1125658  -0.1125504 1.543412e-05        1e-04 0.50005 0.9999 0.0001442767
    #> 3  -0.1125736  -0.1125427 3.086824e-05        2e-04 0.50010 0.9998 0.0002885679
    #> 4  -0.1125813  -0.1125350 4.630236e-05        3e-04 0.50015 0.9997 0.0004328734
    #> 5  -0.1125890  -0.1125273 6.173649e-05        4e-04 0.50020 0.9996 0.0005771935

while the second and third parts of the list contain dataframes and lists for other functions such as generating density functions or for other functions such as `curve_table()`.

    head(object[[2]], 5)
    #>            x
    #> 1 -0.1125581
    #> 2 -0.1125658
    #> 3 -0.1125736
    #> 4 -0.1125813
    #> 5 -0.1125890

    head(object[[3]], 5)
    #>      Lower Limit Upper Limit Interval Width Interval Level (%)   CDF P-value
    #> 2501      -0.132      -0.093          0.039                 25 0.625    0.75
    #> 5001      -0.154      -0.071          0.083                 50 0.750    0.50
    #> 7501      -0.183      -0.042          0.142                 75 0.875    0.25
    #> 8001      -0.192      -0.034          0.158                 80 0.900    0.20
    #> 8501      -0.201      -0.024          0.177                 85 0.925    0.15
    #>      S-value (bits)
    #> 2501          0.415
    #> 5001          1.000
    #> 7501          2.000
    #> 8001          2.322
    #> 8501          2.737

# Distorted Plots

If you encounter issues when plotting the functions, it is because there are a large number of points being plotted, which could lead to the graph being slightly distorted or not loading at all. The simplest solution to this is to refresh the plot and try the function again.

This applies to the `ggcurve()`, `curve_compare()`, and `plot_compare()` functions.

I would also recommend saving plots using the `cowplot::save_plot()` function with the actual `ggcurve()` object. It has better default settings than the `ggsave()` function.

# Slow Performance

Because this package is computing thousands of interval estimates via iterations and bootstrapping, it requires a lot of computational power. Luckily, `concurve` supports parallelization, although it is disabled by default because some users, such as those who use Windows, are unable to use it.

However, if you are able to use parallelization, you can enable it with the following script

    library(parallel)
    options(mc.cores = detectCores())

The script will detect the number of cores on your machine via the `parallel` package and use them to speed up the computations, especially for bootstrapping.

However, if you would like to speed up the computations and are unable to use parallelization, then you can reduce the number of `steps` in the each of the `concurve` functions, which will drastically reduce the time it takes to complete the operation. By default, most of the `steps` arguments are set to 10000.

For example, here I changed the number of steps to 100, which is the minimum needed to plot a function, and the process is now much quicker. We can evaluate this using a microbenchmark. Here I use the `bench` package and the `mark()` function. Because we are using parallelization, we must also set the `memory` argument to `FALSE`.

    library(bench)
    func1 <- bench::mark(df1 <- curve_rev(point = 1.61, LL = 0.997, UL = 2.59,
                                          measure = "ratio", steps = 100), memory = FALSE)

    func2 <- bench::mark(df1 <- curve_rev(point = 1.61, LL = 0.997, UL = 2.59,
                                          measure = "ratio", steps = 10000), memory = FALSE)

    func1
    #> # A tibble: 1 x 6
    #> # … with 6 more variables: expression <bch:expr>, min <bch:tm>,
    #> #   median <bch:tm>, `itr/sec` <dbl>, mem_alloc <bch:byt>, `gc/sec` <dbl>
    func2
    #> # A tibble: 1 x 6
    #> # … with 6 more variables: expression <bch:expr>, min <bch:tm>,
    #> #   median <bch:tm>, `itr/sec` <dbl>, mem_alloc <bch:byt>, `gc/sec` <dbl>

# Bugs

If you encounter any other bugs, please report them at https://github.com/zadrafi/concurve/issues

# Session info

    #> R version 3.6.3 (2020-02-29)
    #> Platform: x86_64-apple-darwin15.6.0 (64-bit)
    #> Running under: macOS Catalina 10.15.4
    #>
    #> Matrix products: default
    #> BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
    #> LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
    #>
    #> locale:
    #> [1] C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    #>
    #> attached base packages:
    #> [1] stats     graphics  grDevices utils     datasets  methods   base
    #>
    #> other attached packages:
    #>  [1] bench_1.1.1           survival_3.1-12       carData_3.0-3
    #>  [4] metafor_2.4-0         Matrix_1.2-18         ProfileLikelihood_1.1
    #>  [7] MASS_7.3-51.5         nlme_3.1-147          cowplot_1.0.0
    #> [10] ggplot2_3.3.0         Lock5Data_2.8         concurve_2.5.0
    #>
    #> loaded via a namespace (and not attached):
    #>  [1] Rcpp_1.0.4.6      lattice_0.20-41   tidyr_1.0.2       zoo_1.8-7
    #>  [5] utf8_1.1.4        assertthat_0.2.1  digest_0.6.25     R6_2.4.1
    #>  [9] survminer_0.4.6   backports_1.1.6   evaluate_0.14     highr_0.8
    #> [13] pillar_1.4.3      gdtools_0.2.2     rlang_0.4.5       curl_4.3
    #> [17] uuid_0.1-4        data.table_1.12.8 magick_2.3        flextable_0.5.9
    #> [21] rmarkdown_2.1     labeling_0.3      splines_3.6.3     stringr_1.4.0
    #> [25] bcaboot_0.2-1     munsell_0.5.0     broom_0.5.5       compiler_3.6.3
    #> [29] xfun_0.13         pkgconfig_2.0.3   systemfonts_0.2.0 base64enc_0.1-3
    #> [33] htmltools_0.4.0   tidyselect_1.0.0  tibble_3.0.0      gridExtra_2.3
    #> [37] km.ci_0.5-2       fansi_0.4.1       withr_2.1.2       crayon_1.3.4
    #> [41] dplyr_0.8.5       ggpubr_0.2.5      grid_3.6.3        xtable_1.8-4
    #> [45] gtable_0.3.0      lifecycle_0.2.0   magrittr_1.5      KMsurv_0.1-5
    #> [49] scales_1.1.0      zip_2.0.4         cli_2.0.2         stringi_1.4.6
    #> [53] farver_2.0.3      ggsignif_0.6.0    xml2_1.3.1        ellipsis_0.3.0
    #> [57] survMisc_0.5.5    generics_0.0.2    vctrs_0.2.4       boot_1.3-24
    #> [61] pbmcapply_1.5.0   tools_3.6.3       glue_1.4.0        officer_0.3.8
    #> [65] purrr_0.3.3       parallel_3.6.3    yaml_2.2.1        colorspace_1.4-1
    #> [69] knitr_1.28