Skip to contents

Performs simulations to compute a projection pursuit index on structured (sampled) data and on random noise, allowing a comparison of index scale across contexts.

Usage

ppi_scale(
  data,
  index_fun,
  noise_fun = NULL,
  n_sim = 100,
  n_obs = 500,
  index_args = list(),
  seed = NULL,
  workers = 1
)

Arguments

data

A data frame or tibble with at least two numeric columns.

index_fun

A function returning a numeric scalar index. It may accept either a 2-column matrix/data frame, or two numeric vectors (x, y).

noise_fun

Optional function for generating noise data. It should take n_obs as input and return a 2-column matrix or data frame. By default, standard bivariate Gaussian noise is used.

n_sim

Integer. Number of simulations. Default is 100.

n_obs

Integer. Number of observations per simulation. Default is 500.

index_args

A named list of additional arguments passed to index_fun.

seed

Optional integer seed for reproducibility.

workers

Integer. Number of parallel workers to use. Default is 1.

Value

A tibble with columns:

  • simulation: simulation number

  • var_i, var_j: variable names

  • var_pair: pair name as a string

  • sigma: "structure" for structured data, "noise" for noisy data

  • index: index value returned by index_fun

Examples

ppi_scale(
  data_gen("polynomial", degree = 3),
  cassowaryr::sc_stringy,
  n_sim = 2,
  index_args = list(binner = "hex"),
  workers = 2
)
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> Warning: 'function (x, y, out.rm = TRUE, binner = "hex") 
#> {
#>     .Deprecated("sc_stringy06")
#>     sc_stringy06(x, y, out.rm, binner)
#> }' is deprecated.
#> Use 'sc_stringy06' instead.
#> See help("Deprecated")
#> # A tibble: 12 × 6
#>    simulation var_i var_j var_pair sigma     index
#>         <int> <chr> <chr> <chr>    <chr>     <dbl>
#>  1          1 1     2     1-2      structure 1    
#>  2          1 1     2     1-2      noise     0.772
#>  3          1 1     3     1-3      structure 1    
#>  4          1 1     3     1-3      noise     0.712
#>  5          1 2     3     2-3      structure 0.986
#>  6          1 2     3     2-3      noise     0.728
#>  7          2 1     2     1-2      structure 1    
#>  8          2 1     2     1-2      noise     0.747
#>  9          2 1     3     1-3      structure 1    
#> 10          2 1     3     1-3      noise     0.729
#> 11          2 2     3     2-3      structure 0.986
#> 12          2 2     3     2-3      noise     0.723

ppi_scale(
  data_gen("polynomial", degree = 3),
  scag_index("stringy"),
  n_sim = 2
)
#> # A tibble: 12 × 6
#>    simulation var_i var_j var_pair sigma     index
#>         <int> <chr> <chr> <chr>    <chr>     <dbl>
#>  1          1 1     2     1-2      structure 1    
#>  2          1 1     2     1-2      noise     0.730
#>  3          1 1     3     1-3      structure 1    
#>  4          1 1     3     1-3      noise     0.714
#>  5          1 2     3     2-3      structure 0.993
#>  6          1 2     3     2-3      noise     0.711
#>  7          2 1     2     1-2      structure 1    
#>  8          2 1     2     1-2      noise     0.661
#>  9          2 1     3     1-3      structure 1    
#> 10          2 1     3     1-3      noise     0.727
#> 11          2 2     3     2-3      structure 0.993
#> 12          2 2     3     2-3      noise     0.713