Introduction

In statisticalRoughness, scale factorization is handled by the function get_all_R_L which returns a list with the values of \(L\), and, for each value of \(L\), the associated values of \(R\). The calculation is constrained by a maximum for \(L\), Lmax, which is independent of map units: it is just a number on the number line. The second parameter of get_all_R_L is the minimum number of factors that have to be found for a value of \(L\) to be returned. Let’s see one example:

library(statisticalRoughness)
get_all_R_L(20, 3, logfilter = FALSE)
#> $allRs
#> $allRs[[1]]
#> [1] 2 3 4 6
#> 
#> $allRs[[2]]
#> [1] 2 4 8
#> 
#> $allRs[[3]]
#> [1] 2 3 6 9
#> 
#> $allRs[[4]]
#> [1]  2  4  5 10
#> 
#> 
#> $allL
#> [1] 12 16 18 20

There are 4 numbers that have at least 3 factors between 1 and 20.

logfilter option

The logfilter = FALSE option, along with the options detailed below, handles a number of speed up factorization when \(L\) becomes large.

logfilter = TRUE tries to find \(n\) logarithmically spaced factors, with \(n\) controlled by the len parameter Let’s see it in action with Lmax = 1E4:

get_all_R_L(1e4, 55, logfilter = FALSE, len = 3)
#> $allRs
#> $allRs[[1]]
#>  [1]    2    3    4    5    6    7    8    9   10   12   14   15   16   18   20
#> [16]   21   24   28   30   35   36   40   42   45   48   56   60   63   70   72
#> [31]   80   84   90  105  112  120  126  140  144  168  180  210  240  252  280
#> [46]  315  336  360  420  504  560  630  720  840 1008 1260 1680 2520
#> 
#> $allRs[[2]]
#>  [1]    2    3    4    5    6    7    8    9   10   12   14   15   18   20   21
#> [16]   24   27   28   30   35   36   40   42   45   54   56   60   63   70   72
#> [31]   84   90  105  108  120  126  135  140  168  180  189  210  216  252  270
#> [46]  280  315  360  378  420  504  540  630  756  840  945 1080 1260 1512 1890
#> [61] 2520 3780
#> 
#> $allRs[[3]]
#>  [1]    2    3    4    5    6    8    9   10   11   12   15   16   18   20   22
#> [16]   24   30   33   36   40   44   45   48   55   60   66   72   80   88   90
#> [31]   99  110  120  132  144  165  176  180  198  220  240  264  330  360  396
#> [46]  440  495  528  660  720  792  880  990 1320 1584 1980 2640 3960
#> 
#> $allRs[[4]]
#>  [1]    2    3    4    5    6    7    8   10   12   14   15   16   20   21   24
#> [16]   25   28   30   35   40   42   48   50   56   60   70   75   80   84  100
#> [31]  105  112  120  140  150  168  175  200  210  240  280  300  336  350  400
#> [46]  420  525  560  600  700  840 1050 1200 1400 1680 2100 2800 4200
#> 
#> $allRs[[5]]
#>  [1]    2    3    4    5    6    7    8   10   11   12   14   15   20   21   22
#> [16]   24   28   30   33   35   40   42   44   55   56   60   66   70   77   84
#> [31]   88  105  110  120  132  140  154  165  168  210  220  231  264  280  308
#> [46]  330  385  420  440  462  616  660  770  840  924 1155 1320 1540 1848 2310
#> [61] 3080 4620
#> 
#> $allRs[[6]]
#>  [1]    2    3    4    5    6    8    9   10   12   13   15   16   18   20   24
#> [16]   26   30   36   39   40   45   48   52   60   65   72   78   80   90  104
#> [31]  117  120  130  144  156  180  195  208  234  240  260  312  360  390  468
#> [46]  520  585  624  720  780  936 1040 1170 1560 1872 2340 3120 4680
#> 
#> 
#> $allL
#> [1] 5040 7560 7920 8400 9240 9360
get_all_R_L(1e4, 55, logfilter = TRUE, len = 3)
#> $allRs
#> $allRs[[1]]
#>  [1]    2    3    4    5    6    7    8    9   10   12   14   15   16   18   20
#> [16]   21   24   28   30   35   36   40   42   45   48   56   60   63   70   72
#> [31]   80   84   90  105  112  120  126  140  144  168  180  210  240  252  280
#> [46]  315  336  360  420  504  560  630  720  840 1008 1260 1680 2520
#> 
#> $allRs[[2]]
#>  [1]    2    3    4    5    6    7    8    9   10   12   14   15   18   20   21
#> [16]   24   27   28   30   35   36   40   42   45   54   56   60   63   70   72
#> [31]   84   90  105  108  120  126  135  140  168  180  189  210  216  252  270
#> [46]  280  315  360  378  420  504  540  630  756  840  945 1080 1260 1512 1890
#> [61] 2520 3780
#> 
#> $allRs[[3]]
#>  [1]    2    3    4    5    6    8    9   10   12   13   15   16   18   20   24
#> [16]   26   30   36   39   40   45   48   52   60   65   72   78   80   90  104
#> [31]  117  120  130  144  156  180  195  208  234  240  260  312  360  390  468
#> [46]  520  585  624  720  780  936 1040 1170 1560 1872 2340 3120 4680
#> 
#> 
#> $allL
#> [1] 5040 7560 9360

In the first case, len has no effect and 6 are returned. In the second case, only 3 logarithmically spaced values are returned.

only option

The only options speeds up the execution by looking directly at multiples of 6 and 10 if only = 610 and at multiples of 12 if only = 12. Because these numbers have the most numbers of factors at the start of the number line, their factors also do have a greater number of factors. Focusing on these only, speeds up the factorization. More details can be found here.

library(microbenchmark)
tm <- microbenchmark(
    get_all_R_L(1e4, 5, only = NULL),
    get_all_R_L(1e4, 5, only = 610),
    get_all_R_L(1e4, 5, only = 12),
    times = 10
)
ggplot2::autoplot(tm) + ggpubr::theme_pubr()
#> Coordinate system already present. Adding new coordinate system, which will replace the existing one.