statsailr_procs_base 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/statsailr_procs_base/proc_setting/proc_cat.R +54 -51
- data/lib/statsailr_procs_base/proc_setting/proc_common/dev_copy.R +8 -5
- data/lib/statsailr_procs_base/proc_setting/proc_common/factor.R +9 -6
- data/lib/statsailr_procs_base/proc_setting/proc_common/numeric.R +9 -6
- data/lib/statsailr_procs_base/proc_setting/proc_filter.R +34 -31
- data/lib/statsailr_procs_base/proc_setting/proc_ggplot.R +35 -32
- data/lib/statsailr_procs_base/proc_setting/proc_ggplot.rb +1 -0
- data/lib/statsailr_procs_base/proc_setting/proc_group.R +33 -34
- data/lib/statsailr_procs_base/proc_setting/proc_mult.R +13 -12
- data/lib/statsailr_procs_base/proc_setting/proc_plot.R +52 -49
- data/lib/statsailr_procs_base/proc_setting/proc_print.R +58 -56
- data/lib/statsailr_procs_base/proc_setting/proc_sort.R +29 -26
- data/lib/statsailr_procs_base/proc_setting/proc_two.R +30 -28
- data/lib/statsailr_procs_base/proc_setting/proc_uni.R +101 -102
- data/lib/statsailr_procs_base/proc_setting/proc_uni.rb +1 -0
- data/lib/statsailr_procs_base/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c71268a7ddcceaacdd0e8967bf3ce232667d43fe879e932b3acfc80a45235ecc
|
4
|
+
data.tar.gz: 822e0b2ab2bc4f040bd310e9fbe5acd883e2a4056e1c3c0a9abd70ac95945a07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df438d9db6db33303a05ed4c3584f0cea3e336fc0915c2fa33da7484eb60d409b976cc97d87e02917e2babda8586dcfe5a148c2bfdfcee4094d1e55b8ba27dc7
|
7
|
+
data.tar.gz: 0731ce51dadc3ae5611ccbfcfd7a971065534efea91131656cc846eccfb9feb42488cee0c4f952106a435f1790122ac46f3d9124b80aaab80418c59a77025c6f
|
@@ -1,65 +1,68 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
STS_RC_Cat = setRefClass("STS_RC_Cat")
|
2
|
+
STS_RC_Cat$methods(
|
3
|
+
table = function( data , vars , missing = FALSE, ... ){
|
4
|
+
if( (! is.character(vars)) || length(vars) != 2 ){
|
5
|
+
stop("vars argument requires character vector with size of 2")
|
6
|
+
}
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
df_for_table = data[ , vars ]
|
9
|
+
if( missing ){
|
10
|
+
freq_ori = base::table(df_for_table, useNA = "ifany")
|
11
|
+
}else{
|
12
|
+
freq_ori = base::table(df_for_table)
|
13
|
+
}
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
freq = addmargins( freq_ori )
|
16
|
+
allper = format( addmargins( prop.table( freq_ori) * 100), digits = 4)
|
17
|
+
rowper = format( addmargins( prop.table( freq_ori, 1) * 100), digits = 4)
|
18
|
+
colper = format( addmargins( prop.table( freq_ori, 2) * 100), digits = 4)
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
nrow = nrow(freq)
|
21
|
+
ncol = ncol(freq)
|
22
|
+
nrow_ori = nrow(freq_ori)
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
temp = as.array( numeric( nrow * ncol * 4 ))
|
25
|
+
dim( temp ) = c( nrow * 4, ncol )
|
26
|
+
result = base::as.table( temp )
|
27
27
|
|
28
|
-
|
28
|
+
colnames(result) = c( colnames( freq_ori ) , "Total")
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
row_label1 = c( rep("%",nrow_ori ) , "%")
|
31
|
+
row_label2 = c( rep("Row%",nrow_ori ) , "")
|
32
|
+
row_label3 = c( rep("Col%",nrow_ori ) , "")
|
33
33
|
|
34
|
-
|
34
|
+
rownames(result) = as.vector( mapply( c, c( rownames( freq_ori ), "Total" ), row_label1 , row_label2 , row_label3 ))
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
}
|
41
|
-
for( icol in seq(1, ncol) ){
|
42
|
-
result[ (irow-1)*4 + 2, icol] = allper[irow, icol]
|
43
|
-
}
|
44
|
-
for( icol in seq(1, ncol) ){
|
45
|
-
if(irow != nrow && icol != ncol){
|
46
|
-
result[ (irow-1)*4 + 3, icol] = rowper[irow, icol]
|
47
|
-
}else{
|
48
|
-
result[ (irow-1)*4 + 3, icol] = NA
|
36
|
+
cat( paste( "\t", names(freq), "\n", sep = "\t", collapse = "\t" ))
|
37
|
+
for( irow in seq(1, nrow) ){
|
38
|
+
for( icol in seq(1, ncol) ){
|
39
|
+
result[ (irow-1)*4 + 1, icol] = freq[irow, icol]
|
49
40
|
}
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
41
|
+
for( icol in seq(1, ncol) ){
|
42
|
+
result[ (irow-1)*4 + 2, icol] = allper[irow, icol]
|
43
|
+
}
|
44
|
+
for( icol in seq(1, ncol) ){
|
45
|
+
if(irow != nrow && icol != ncol){
|
46
|
+
result[ (irow-1)*4 + 3, icol] = rowper[irow, icol]
|
47
|
+
}else{
|
48
|
+
result[ (irow-1)*4 + 3, icol] = NA
|
49
|
+
}
|
50
|
+
}
|
51
|
+
for( icol in seq(1, ncol) ){
|
52
|
+
if(icol != ncol && irow!= nrow){
|
53
|
+
result[ (irow-1)*4 + 4, icol] = colper[irow, icol]
|
54
|
+
}else{
|
55
|
+
result[ (irow-1)*4 + 4, icol] = NA
|
56
|
+
}
|
56
57
|
}
|
57
58
|
}
|
58
|
-
}
|
59
59
|
|
60
|
-
|
61
|
-
|
60
|
+
cat( paste( vars[1] , " vs ", vars[2], "\n" ) )
|
61
|
+
print( result )
|
62
|
+
|
63
|
+
return( freq_ori )
|
64
|
+
}
|
65
|
+
)
|
62
66
|
|
63
|
-
|
64
|
-
}
|
67
|
+
sts_cat = STS_RC_Cat()
|
65
68
|
|
@@ -1,6 +1,9 @@
|
|
1
|
-
|
1
|
+
STS_RC_DevCopy = setRefClass("STS_RC_DevCopy")
|
2
|
+
STS_RC_DevCopy$methods(
|
3
|
+
dev_copy = function( device, ... ){
|
4
|
+
dev.copy( device , ...)
|
5
|
+
dev.off()
|
6
|
+
}
|
7
|
+
)
|
2
8
|
|
3
|
-
sts_dev_copy
|
4
|
-
dev.copy( device , ...)
|
5
|
-
dev.off()
|
6
|
-
}
|
9
|
+
sts_dev_copy = STS_RC_DevCopy()
|
@@ -1,7 +1,10 @@
|
|
1
|
-
|
1
|
+
STS_RC_Factor = setRefClass("STS_RC_Factor")
|
2
|
+
STS_RC_Factor$methods(
|
3
|
+
convert_to_factor = function( data, vars ){
|
4
|
+
data[vars] = lapply(data[vars], as.factor)
|
5
|
+
print( paste( "as.factor is applied to", paste( vars, collapse=",") , sep=" ") )
|
6
|
+
return( data )
|
7
|
+
}
|
8
|
+
)
|
2
9
|
|
3
|
-
sts_factor
|
4
|
-
data[vars] = lapply(data[vars], as.factor)
|
5
|
-
print( paste( "as.factor is applied to", paste( vars, collapse=",") , sep=" ") )
|
6
|
-
return( data )
|
7
|
-
}
|
10
|
+
sts_factor = STS_RC_Factor()
|
@@ -1,7 +1,10 @@
|
|
1
|
-
|
1
|
+
STS_RC_Numeric = setRefClass("STS_RC_Numeric")
|
2
|
+
STS_RC_Numeric$methods(
|
3
|
+
convert_to_numeric = function( data, vars ){
|
4
|
+
data[vars] = lapply(data[vars], as.numeric)
|
5
|
+
print( paste( "as.numeric is applied to", paste( vars, collapse=",") , sep=" ") )
|
6
|
+
return( data )
|
7
|
+
}
|
8
|
+
)
|
2
9
|
|
3
|
-
sts_numeric
|
4
|
-
data[vars] = lapply(data[vars], as.numeric)
|
5
|
-
print( paste( "as.numeric is applied to", paste( vars, collapse=",") , sep=" ") )
|
6
|
-
return( data )
|
7
|
-
}
|
10
|
+
sts_numeric = STS_RC_Numeric()
|
@@ -1,39 +1,42 @@
|
|
1
|
-
|
1
|
+
STS_RC_Filter = setRefClass("STS_RC_Filter")
|
2
|
+
STS_RC_Filter$methods(
|
3
|
+
wrap_filter = function( data, cond ){
|
4
|
+
lang_cond = rlang::parse_expr( cond )
|
5
|
+
df = dplyr::filter( data, !! lang_cond )
|
6
|
+
return(df)
|
7
|
+
},
|
2
8
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
}
|
9
|
+
wrap_select = function( data, cond ){
|
10
|
+
lang_cond = rlang::parse_exprs(cond)
|
11
|
+
df = dplyr::select(data, !!! lang_cond)
|
12
|
+
return(df)
|
13
|
+
},
|
8
14
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
|
15
|
-
sts_filter$assign_to = function(var, df){
|
16
|
-
if( (! is.character(var)) || length(var) != 1 ){
|
17
|
-
stop("var argument requires character vector with size of 1")
|
18
|
-
}
|
15
|
+
assign_to = function(var, df){
|
16
|
+
if( (! is.character(var)) || length(var) != 1 ){
|
17
|
+
stop("var argument requires character vector with size of 1")
|
18
|
+
}
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
20
|
+
global_env = globalenv()
|
21
|
+
global_env[[ var[1] ]] = df
|
22
|
+
return(df)
|
23
|
+
},
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
finalizer = function( df, last_inst, out ){
|
26
|
+
if( last_inst != "assign_to" ){
|
27
|
+
if( is.null(out) ){
|
28
|
+
cat("The last result is print out, and is not assigned to any variable.\n")
|
29
|
+
print(head(df))
|
30
|
+
cat("Use out= option for PROC COMMAND or use assing_to instruction\n")
|
31
|
+
cat("to assign the last result to some variable.\n")
|
32
|
+
}else{
|
33
|
+
sts_filter$assign_to( out, df )
|
34
|
+
}
|
32
35
|
}else{
|
33
|
-
|
36
|
+
# OK. The result dataframe is already assigned using assign_to instruction.
|
34
37
|
}
|
35
|
-
}else{
|
36
|
-
# OK. The result dataframe is already assigned using assign_to instruction.
|
37
38
|
}
|
38
|
-
|
39
|
+
)
|
40
|
+
|
41
|
+
sts_filter = STS_RC_Filter()
|
39
42
|
|
@@ -1,39 +1,42 @@
|
|
1
|
-
sts_ggplot = new.env()
|
2
|
-
|
3
1
|
library(rlang)
|
4
2
|
library(ggplot2)
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
STS_RC_Ggplot = setRefClass("STS_RC_Ggplot")
|
5
|
+
STS_RC_Ggplot$methods(
|
6
|
+
mapping = function( data, assoc ){
|
7
|
+
assoc_lang = rlang::parse_exprs(assoc)
|
8
|
+
# https://github.com/tidyverse/ggplot2/issues/2675
|
9
|
+
gg = ggplot2::ggplot(data, ggplot2::aes( ,, !!! assoc_lang ))
|
10
|
+
return( gg )
|
11
|
+
},
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
}
|
13
|
+
geom_point_wrapper = function( gg, params = NULL, ... ){
|
14
|
+
if( is.null(params) ){
|
15
|
+
gg = gg + ggplot2::geom_point()
|
16
|
+
}else{
|
17
|
+
params_lang = rlang::parse_exprs(params)
|
18
|
+
# https://stackoverflow.com/questions/68379666/how-to-specify-a-package-or-namespace-for-rlangexec
|
19
|
+
# https://stackoverflow.com/questions/70202220/big-bang-operator-for-ggplot2-geom-point-function
|
20
|
+
# real_fun <- get("geom_point", envir=as.environment(paste0("package:", "ggplot2")))
|
21
|
+
# gg = gg + rlang::exec(real_fun, !!! params_lang , ...)
|
22
|
+
gg = gg + rlang::inject(ggplot2::geom_point( !!! params_lang , ...))
|
23
|
+
}
|
24
|
+
return( gg )
|
25
|
+
},
|
26
|
+
|
27
|
+
geom_histogram_wrapper = function( gg, params = NULL, ...){
|
28
|
+
if( is.null(params) ){
|
29
|
+
gg = gg + ggplot2::geom_histogram()
|
30
|
+
}else{
|
31
|
+
params_lang = rlang::parse_exprs(params)
|
32
|
+
gg = gg + rlang::inject(ggplot2::geom_histogram( !!! params_lang , ...))
|
33
|
+
}
|
34
|
+
return( gg )
|
35
|
+
},
|
26
36
|
|
27
|
-
|
28
|
-
|
29
|
-
gg = gg + ggplot2::geom_histogram()
|
30
|
-
}else{
|
31
|
-
params_lang = rlang::parse_exprs(params)
|
32
|
-
gg = gg + rlang::inject(ggplot2::geom_histogram( !!! params_lang , ...))
|
37
|
+
finalizer = function( gg ){
|
38
|
+
plot(gg)
|
33
39
|
}
|
34
|
-
|
35
|
-
}
|
40
|
+
)
|
36
41
|
|
37
|
-
sts_ggplot
|
38
|
-
plot(gg)
|
39
|
-
}
|
42
|
+
sts_ggplot = STS_RC_Ggplot()
|
@@ -1,55 +1,54 @@
|
|
1
|
-
sts_group = new.env()
|
2
|
-
|
3
1
|
library(rlang)
|
4
2
|
|
5
|
-
|
3
|
+
STS_RC_Group = setRefClass("STS_RC_Group")
|
4
|
+
STS_RC_Group$methods(
|
5
|
+
wrap_group_by = function(data, vars){
|
6
6
|
vars_lang = rlang::parse_exprs(vars)
|
7
7
|
grouped_data = rlang::inject(dplyr::group_by( data, !!! vars_lang ))
|
8
8
|
return(grouped_data)
|
9
|
-
}
|
10
|
-
|
9
|
+
},
|
11
10
|
|
12
|
-
|
11
|
+
wrap_mutate = function(data, params){
|
13
12
|
params_lang = rlang::parse_exprs(params)
|
14
13
|
mutated_data = rlang::inject(dplyr::mutate( data, !!! params_lang ))
|
15
14
|
return(mutated_data)
|
16
|
-
}
|
15
|
+
},
|
17
16
|
|
18
|
-
|
19
|
-
sts_group$wrap_summarize = function(data, params){
|
17
|
+
wrap_summarize = function(data, params){
|
20
18
|
params_lang = rlang::parse_exprs(params)
|
21
19
|
result = rlang::inject(dplyr::summarize( data, !!! params_lang ))
|
22
20
|
print(result)
|
23
21
|
return(data)
|
24
|
-
}
|
25
|
-
|
22
|
+
},
|
26
23
|
|
27
|
-
|
28
|
-
|
24
|
+
assign_to = function(var, df){
|
25
|
+
df = as.data.frame(df)
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
global_env = globalenv()
|
35
|
-
global_env[[ var[1] ]] = df
|
36
|
-
return(df)
|
37
|
-
}
|
38
|
-
|
39
|
-
sts_group$finalizer = function( df, last_inst, out ){
|
40
|
-
df = as.data.frame(df)
|
27
|
+
if( (! is.character(var)) || length(var) != 1 ){
|
28
|
+
stop("var argument requires character vector with size of 1")
|
29
|
+
}
|
41
30
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
31
|
+
global_env = globalenv()
|
32
|
+
global_env[[ var[1] ]] = df
|
33
|
+
return(df)
|
34
|
+
},
|
35
|
+
|
36
|
+
finalizer = function( df, last_inst, out ){
|
37
|
+
df = as.data.frame(df)
|
38
|
+
|
39
|
+
if( last_inst != "assign_to" ){
|
40
|
+
if( is.null(out) ){
|
41
|
+
cat("The last result is print out, and is not assigned to any variable.\n")
|
42
|
+
print(head(df))
|
43
|
+
cat("Use out= option for PROC COMMAND or use assing_to instruction\n")
|
44
|
+
cat("to assign the last result to some variable.\n")
|
45
|
+
}else{
|
46
|
+
sts_group$assign_to( out, df )
|
47
|
+
}
|
48
48
|
}else{
|
49
|
-
|
49
|
+
# OK. The result dataframe is already assigned using assign_to instruction.
|
50
50
|
}
|
51
|
-
}else{
|
52
|
-
# OK. The result dataframe is already assigned using assign_to instruction.
|
53
51
|
}
|
54
|
-
|
52
|
+
)
|
55
53
|
|
54
|
+
sts_group = STS_RC_Group()
|
@@ -1,12 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
}
|
11
|
-
|
12
|
-
|
1
|
+
STS_RC_Mult = setRefClass("STS_RC_Mult")
|
2
|
+
STS_RC_Mult$methods(
|
3
|
+
p_adjust = function( x , method ){
|
4
|
+
ori_p = summary(x)[[1]][['Pr(>F)']]
|
5
|
+
result = p.adjust( ori_p, method )
|
6
|
+
|
7
|
+
cat( "p adjustment\n" )
|
8
|
+
cat( paste( "Method:", method, "\n", sep=" ", collapse=" " ) )
|
9
|
+
return(result)
|
10
|
+
}
|
11
|
+
)
|
12
|
+
|
13
|
+
sts_mult = STS_RC_Mult()
|
@@ -1,52 +1,55 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
1
|
+
STS_RC_Plot = setRefClass("STS_RC_Plot")
|
2
|
+
STS_RC_Plot$methods(
|
3
|
+
legend = function( legend , ... ){
|
4
|
+
if( (! is.character(legend)) ){
|
5
|
+
stop("legend argument requires character vector")
|
6
|
+
}
|
7
|
+
|
8
|
+
args = list(...)
|
9
|
+
args$legend = legend
|
10
|
+
args$x = if_exist_else ( "x", args, paste( "topleft" ))
|
11
|
+
|
12
|
+
do.call( get_pkg_fun( "graphics::legend") , args )
|
13
|
+
},
|
14
|
+
|
15
|
+
hist = function( data , var , ... ){
|
16
|
+
if( (! is.character(var)) || length(var) != 1 ){
|
17
|
+
stop("vars argument requires character vector with size of 1")
|
18
|
+
}
|
19
|
+
|
20
|
+
args = list(...)
|
21
|
+
args$x = data[[var]]
|
22
|
+
args$main = if_exist_else ( "main", args, paste( "Frequency of" , var ))
|
23
|
+
args$xlab = if_exist_else ( "xlab", args, paste( var ))
|
24
|
+
|
25
|
+
do.call( get_pkg_fun( "graphics::hist") , args )
|
26
|
+
},
|
27
|
+
|
28
|
+
box = function( data , var , ... ){
|
29
|
+
if( (! is.character(var)) || length(var) != 1 ){
|
30
|
+
stop("vars argument requires character vector with size of 1")
|
31
|
+
}
|
32
|
+
|
33
|
+
args = list(...)
|
34
|
+
args$x = data[[var]]
|
35
|
+
args$main = if_exist_else ( "main", args, paste( var ))
|
36
|
+
args$lex.order = TRUE
|
37
|
+
|
38
|
+
do.call( get_pkg_fun( "graphics::boxplot"), args )
|
39
|
+
},
|
40
|
+
|
41
|
+
scatter = function( data , vars , ... ){
|
42
|
+
if( (! is.character(vars)) || length(vars) != 2 ){
|
43
|
+
stop("vars argument requires character vector with size of 2")
|
44
|
+
}
|
45
|
+
|
46
|
+
args = list(...)
|
47
|
+
args$x = data[vars]
|
48
|
+
args$main = if_exist_else ( "main", args, paste( vars[1], "vs", vars[2] ))
|
49
|
+
|
50
|
+
do.call( get_pkg_fun( "graphics::plot"), args )
|
31
51
|
}
|
52
|
+
)
|
32
53
|
|
33
|
-
|
34
|
-
args$x = data[[var]]
|
35
|
-
args$main = if_exist_else ( "main", args, paste( var ))
|
36
|
-
args$lex.order = TRUE
|
37
|
-
|
38
|
-
do.call( get_pkg_fun( "graphics::boxplot"), args )
|
39
|
-
}
|
40
|
-
|
41
|
-
sts_plot$scatter = function( data , vars , ... ){
|
42
|
-
if( (! is.character(vars)) || length(vars) != 2 ){
|
43
|
-
stop("vars argument requires character vector with size of 2")
|
44
|
-
}
|
45
|
-
|
46
|
-
args = list(...)
|
47
|
-
args$x = data[vars]
|
48
|
-
args$main = if_exist_else ( "main", args, paste( vars[1], "vs", vars[2] ))
|
49
|
-
|
50
|
-
do.call( get_pkg_fun( "graphics::plot"), args )
|
51
|
-
}
|
54
|
+
sts_plot = STS_RC_Plot()
|
52
55
|
|
@@ -1,60 +1,62 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# positions are passed as strvec which is already splitted by spaces and signs
|
6
|
-
# group these elements
|
7
|
-
|
8
|
-
shift_vec = function( x, n , fill=NA ){
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
}
|
20
|
-
|
21
|
-
colon_pos = (positions == ":")
|
22
|
-
colon_after_pos = shift_vec( colon_pos , 1, F )
|
23
|
-
group_num = cumsum( !( colon_pos | colon_after_pos) )
|
24
|
-
|
25
|
-
position_strvec = sapply( split(positions, group_num) , function(elem){ paste( elem, collapse="" )} )
|
26
|
-
names( position_strvec) = position_strvecp
|
27
|
-
|
28
|
-
# Convert them to a list of int vectors
|
29
|
-
|
30
|
-
position_list = lapply(position_strvec, function(elem){
|
31
|
-
range_sep = ":"
|
32
|
-
if( grepl( range_sep, elem, fixed = TRUE) ){ # grepl(pattern, x)
|
33
|
-
range = strsplit(elem, range_sep, fixed=TRUE)[[1]]
|
34
|
-
if( length(range) != 2){
|
35
|
-
print("Range should be specified with x:y form (meaning from x to y).")
|
36
|
-
return( 0 )
|
37
|
-
}else{
|
38
|
-
range_int = strtoi(range)
|
39
|
-
return( seq(range_int[1], range_int[2]) )
|
1
|
+
STS_RC_Print = setRefClass("STS_RC_Print")
|
2
|
+
STS_RC_Print$methods(
|
3
|
+
nth = function( x , positions ){
|
4
|
+
|
5
|
+
# positions are passed as strvec which is already splitted by spaces and signs
|
6
|
+
# group these elements
|
7
|
+
|
8
|
+
shift_vec = function( x, n , fill=NA ){
|
9
|
+
if( n == 0 ){
|
10
|
+
return( x )
|
11
|
+
}else if( n > 0 ){
|
12
|
+
return( c( rep(fill, n), head(x, -n)) )
|
13
|
+
}else if( n < 0 ){
|
14
|
+
return( c( tail(x, length(x) + n), rep(fill, -n)) )
|
15
|
+
}else{
|
16
|
+
print("inappropriate n.")
|
17
|
+
return(x)
|
18
|
+
}
|
40
19
|
}
|
41
|
-
}else{
|
42
|
-
return( strtoi(elem))
|
43
|
-
}
|
44
|
-
})
|
45
|
-
|
46
|
-
# For each int vector, print corresponding rows
|
47
20
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
21
|
+
colon_pos = (positions == ":")
|
22
|
+
colon_after_pos = shift_vec( colon_pos , 1, F )
|
23
|
+
group_num = cumsum( !( colon_pos | colon_after_pos) )
|
24
|
+
|
25
|
+
position_strvec = sapply( split(positions, group_num) , function(elem){ paste( elem, collapse="" )} )
|
26
|
+
|
27
|
+
# Convert them to a list of int vectors
|
28
|
+
|
29
|
+
position_list = lapply(position_strvec, function(elem){
|
30
|
+
range_sep = ":"
|
31
|
+
if( grepl( range_sep, elem, fixed = TRUE) ){ # grepl(pattern, x)
|
32
|
+
range = strsplit(elem, range_sep, fixed=TRUE)[[1]]
|
33
|
+
if( length(range) != 2){
|
34
|
+
print("Range should be specified with x:y form (meaning from x to y).")
|
35
|
+
return( 0 )
|
36
|
+
}else{
|
37
|
+
range_int = strtoi(range)
|
38
|
+
return( seq(range_int[1], range_int[2]) )
|
39
|
+
}
|
40
|
+
}else{
|
41
|
+
return( strtoi(elem))
|
42
|
+
}
|
43
|
+
})
|
44
|
+
|
45
|
+
# For each int vector, print corresponding rows
|
46
|
+
|
47
|
+
lapply( position_list, function(nth){
|
48
|
+
x[ nth , ]
|
49
|
+
})
|
50
|
+
|
51
|
+
},
|
52
|
+
|
53
|
+
random = function( x , n ){
|
54
|
+
row_num = nrow(x)
|
55
|
+
index = ceiling(row_num * runif(n))
|
56
|
+
sorted_index = sort(index)
|
57
|
+
x[ sorted_index , ]
|
58
|
+
}
|
59
|
+
)
|
53
60
|
|
54
|
-
sts_print
|
55
|
-
row_num = nrow(x)
|
56
|
-
index = ceiling(row_num * runif(n))
|
57
|
-
sorted_index = sort(index)
|
58
|
-
x[ sorted_index , ]
|
59
|
-
}
|
61
|
+
sts_print = STS_RC_Print()
|
60
62
|
|
@@ -1,32 +1,35 @@
|
|
1
|
-
|
1
|
+
STS_RC_Sort = setRefClass("STS_RC_Sort")
|
2
|
+
STS_RC_Sort$methods(
|
3
|
+
wrap_arrange = function( data, cond ){
|
4
|
+
lang_cond = rlang::parse_exprs(cond)
|
5
|
+
df = dplyr::arrange(data, !!! lang_cond)
|
6
|
+
return(df)
|
7
|
+
},
|
2
8
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
}
|
8
|
-
|
9
|
-
sts_sort$assign_to = function(var, df){
|
10
|
-
if( (! is.character(var)) || length(var) != 1 ){
|
11
|
-
stop("var argument requires character vector with size of 1")
|
12
|
-
}
|
9
|
+
assign_to = function(var, df){
|
10
|
+
if( (! is.character(var)) || length(var) != 1 ){
|
11
|
+
stop("var argument requires character vector with size of 1")
|
12
|
+
}
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
}
|
14
|
+
global_env = globalenv()
|
15
|
+
global_env[[ var[1] ]] = df
|
16
|
+
return(df)
|
17
|
+
},
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
finalizer = function( df, last_inst, out ){
|
20
|
+
if( last_inst != "assign_to" ){
|
21
|
+
if( is.null(out) ){
|
22
|
+
cat("The last result is print out, and is not assigned to any variable.\n")
|
23
|
+
print(head(df))
|
24
|
+
cat("Use out= option for PROC COMMAND or use assing_to instruction\n")
|
25
|
+
cat("to assign the last result to some variable.\n")
|
26
|
+
}else{
|
27
|
+
sts_sort$assign_to( out, df )
|
28
|
+
}
|
26
29
|
}else{
|
27
|
-
|
30
|
+
# OK. The result dataframe is already assigned using assign_to instruction.
|
28
31
|
}
|
29
|
-
}else{
|
30
|
-
# OK. The result dataframe is already assigned using assign_to instruction.
|
31
32
|
}
|
32
|
-
|
33
|
+
)
|
34
|
+
|
35
|
+
sts_sort = STS_RC_Sort()
|
@@ -1,33 +1,35 @@
|
|
1
|
-
|
1
|
+
STS_RC_Two = setRefClass("STS_RC_Two")
|
2
|
+
STS_RC_Two$methods(
|
3
|
+
t_test = function( data , vars , ... ){
|
4
|
+
if( (! is.character(vars)) || length(vars) != 2 ){
|
5
|
+
stop("vars argument requires character vector with size of 2")
|
6
|
+
}
|
7
|
+
x = vars[1]
|
8
|
+
y = vars[2]
|
9
|
+
result = t.test( data[[x]], data[[y]], ... )
|
10
|
+
return(result)
|
11
|
+
},
|
2
12
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
12
|
-
|
13
|
-
sts_two$paired = function( data , vars , ... ){
|
14
|
-
if( (! is.character(vars)) || length(vars) != 2 ){
|
15
|
-
stop("vars argument requires character vector with size of 2")
|
16
|
-
}
|
17
|
-
x = vars[1]
|
18
|
-
y = vars[2]
|
19
|
-
result = t.test( data[[x]], data[[y]], paired = TRUE, ... )
|
20
|
-
return(result)
|
21
|
-
}
|
13
|
+
paired = function( data , vars , ... ){
|
14
|
+
if( (! is.character(vars)) || length(vars) != 2 ){
|
15
|
+
stop("vars argument requires character vector with size of 2")
|
16
|
+
}
|
17
|
+
x = vars[1]
|
18
|
+
y = vars[2]
|
19
|
+
result = t.test( data[[x]], data[[y]], paired = TRUE, ... )
|
20
|
+
return(result)
|
21
|
+
},
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
wilcox_test = function( data , vars , ... ){
|
24
|
+
if( (! is.character(vars)) || length(vars) != 2 ){
|
25
|
+
stop("vars argument requires character vector with size of 2")
|
26
|
+
}
|
27
|
+
x = vars[1]
|
28
|
+
y = vars[2]
|
29
|
+
result = wilcox.test( data[[x]], data[[y]], ... )
|
30
|
+
return(result)
|
26
31
|
}
|
27
|
-
|
28
|
-
y = vars[2]
|
29
|
-
result = wilcox.test( data[[x]], data[[y]], ... )
|
30
|
-
return(result)
|
31
|
-
}
|
32
|
+
)
|
32
33
|
|
34
|
+
sts_two = STS_RC_Two()
|
33
35
|
|
@@ -1,126 +1,125 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
STS_RC_Uni = setRefClass("STS_RC_Uni")
|
2
|
+
STS_RC_Uni$methods(
|
3
|
+
list2str = function ( lst, exclude=c() ){
|
4
|
+
str = ""
|
5
|
+
for( i in seq(1,length(lst))){
|
6
|
+
if (! names(lst)[i] %in% exclude ){
|
7
|
+
key = names(lst)[i]
|
8
|
+
value = lst[[i]]
|
9
|
+
|
10
|
+
if( length( value ) == 1 ){
|
11
|
+
str = paste0( str, key, "\t", value, "\n")
|
12
|
+
}else if( is.null( attr( value, "names"))){
|
13
|
+
str = paste0( str, key, "\t", paste( value , collapse=" ") , "\n")
|
14
|
+
}else{
|
15
|
+
str = paste0( str, key, "\n" )
|
16
|
+
str = paste0( str, paste( mapply( paste0, "\t", names(value), "\t" , value), collapse="\n") , "\n")
|
17
|
+
}
|
17
18
|
}
|
18
19
|
}
|
19
|
-
|
20
|
-
|
21
|
-
}
|
22
|
-
|
23
|
-
|
24
|
-
sts_uni$var = function( data , vars , hist = FALSE , ... ){
|
25
|
-
if( (! is.character(vars)) || length(vars) == 0 ){
|
26
|
-
stop("vars argument requires character vector")
|
27
|
-
}
|
28
|
-
check_name_existance = vars %in% colnames(data)
|
29
|
-
if( ! all(check_name_existance) ){
|
30
|
-
print( paste( check_name_existance , "\n") )
|
31
|
-
stop("vars argument should be colnames of data")
|
32
|
-
}
|
20
|
+
return( str )
|
21
|
+
},
|
33
22
|
|
34
|
-
|
35
|
-
|
23
|
+
var = function( data , vars , hist = FALSE , ... ){
|
24
|
+
if( (! is.character(vars)) || length(vars) == 0 ){
|
25
|
+
stop("vars argument requires character vector")
|
26
|
+
}
|
27
|
+
check_name_existance = vars %in% colnames(data)
|
28
|
+
if( ! all(check_name_existance) ){
|
29
|
+
print( paste( check_name_existance , "\n") )
|
30
|
+
stop("vars argument should be colnames of data")
|
31
|
+
}
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
result$vec = df[[ var ]]
|
33
|
+
results = list()
|
34
|
+
df = data
|
40
35
|
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
for( var in vars){
|
37
|
+
result = list()
|
38
|
+
result$vec = df[[ var ]]
|
44
39
|
|
45
|
-
|
46
|
-
|
40
|
+
result$mean = mean( df[[ var ]] )
|
41
|
+
result$N = length( df[[ var ]] )
|
42
|
+
missing_pos = is.na(df[[ var ]])
|
47
43
|
|
48
|
-
|
44
|
+
result$missing = sum( missing_pos )
|
45
|
+
result$n = sum( ! missing_pos )
|
49
46
|
|
50
|
-
|
51
|
-
third_quart = quantiles[5]
|
52
|
-
first_quart = quantiles[7]
|
53
|
-
result$max = head(quantiles, 1)
|
54
|
-
result$min = tail(quantiles, 1)
|
47
|
+
non_missing = df[[ var ]][! missing_pos]
|
55
48
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
49
|
+
quantiles = quantile(non_missing, probs = c(1, 0.99, 0.95, 0.90, 0.75, 0.5, 0.25, 0.1, 0.05, 0.01, 0), na.rm = TRUE)
|
50
|
+
third_quart = quantiles[5]
|
51
|
+
first_quart = quantiles[7]
|
52
|
+
result$max = head(quantiles, 1)
|
53
|
+
result$min = tail(quantiles, 1)
|
61
54
|
|
62
|
-
|
63
|
-
|
64
|
-
|
55
|
+
result$mean = mean(non_missing)
|
56
|
+
result$deviation = sd(non_missing)
|
57
|
+
result$median = median(non_missing)
|
58
|
+
result$IQR = c( first_quart ,third_quart )
|
59
|
+
result$quantiles = quantiles
|
65
60
|
|
66
|
-
|
67
|
-
|
61
|
+
# To be implemented
|
62
|
+
# skewness
|
63
|
+
# kurtosis
|
68
64
|
|
69
|
-
|
70
|
-
|
71
|
-
for( i in seq(1, result_num)){
|
72
|
-
result_str = paste0( result_str, names(results)[i], " ", "statistics\n")
|
73
|
-
result_str = paste0( result_str, sts_uni$list2str(results[[i]], exclude=c("vec")), "\n")
|
74
|
-
}
|
65
|
+
results[[var]] = result
|
66
|
+
}
|
75
67
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
68
|
+
result_str = ""
|
69
|
+
result_num = length(results)
|
70
|
+
for( i in seq(1, result_num)){
|
71
|
+
result_str = paste0( result_str, names(results)[i], " ", "statistics\n")
|
72
|
+
result_str = paste0( result_str, sts_uni$list2str(results[[i]], exclude=c("vec")), "\n")
|
81
73
|
}
|
82
|
-
layout( matrix(c(1), ncol = 1))
|
83
|
-
}
|
84
74
|
|
85
|
-
|
86
|
-
|
87
|
-
|
75
|
+
# output
|
76
|
+
if( hist ){
|
77
|
+
layout( matrix(seq(1, result_num), ncol = 1))
|
78
|
+
for( i in seq(1,result_num)){
|
79
|
+
hist( results[[ i ]]$vec , main = paste( "Histogram of" , names(results)[i] ), xlab=names(results)[i] )
|
80
|
+
}
|
81
|
+
layout( matrix(c(1), ncol = 1))
|
82
|
+
}
|
88
83
|
|
84
|
+
cat( result_str ) # output is done using cat()
|
85
|
+
return(results) # return value to be used by other instructions is results
|
86
|
+
},
|
89
87
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
}
|
88
|
+
qqplot = function( results , var = NULL , qqline = FALSE, ... ){
|
89
|
+
if ( (! is.null(var)) && (length(var) != 1) ){
|
90
|
+
stop("main argument needs to be length of 1 character vector")
|
91
|
+
}
|
92
|
+
if( is.null(var) ){
|
93
|
+
vec = results[[1]]$vec
|
94
|
+
}else{
|
95
|
+
vec = results[[var]]$vec
|
96
|
+
}
|
97
|
+
qqnorm(vec)
|
98
|
+
if( qqline ){
|
99
|
+
qqline(vec)
|
100
|
+
}
|
101
|
+
},
|
104
102
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
103
|
+
hist = function( data, vars ){
|
104
|
+
if ( (! is.null(var)) && (length(var) != 1) ){
|
105
|
+
stop("main argument needs to be length of 1 character vector")
|
106
|
+
}
|
109
107
|
|
110
|
-
|
111
|
-
|
108
|
+
size = length(vars)
|
109
|
+
par(mfrow(size, 1))
|
112
110
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
111
|
+
for( i in seq(1, size)){
|
112
|
+
var = vars[[i]]
|
113
|
+
g = data[[var]]
|
114
|
+
h <- hist(g, breaks = 10, density = 10,
|
117
115
|
col = "lightgray", xlab = "Accuracy", main = "Overall")
|
118
|
-
|
119
|
-
|
120
|
-
|
116
|
+
xfit <- seq(min(g), max(g), length = 40)
|
117
|
+
yfit <- dnorm(xfit, mean = mean(g), sd = sd(g))
|
118
|
+
yfit <- yfit * diff(h$mids[1:2]) * length(g)
|
121
119
|
|
122
|
-
|
120
|
+
lines(xfit, yfit, col = "black", lwd = 2)
|
121
|
+
}
|
123
122
|
}
|
123
|
+
)
|
124
124
|
|
125
|
-
|
126
|
-
|
125
|
+
sts_uni = STS_RC_Uni()
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsailr_procs_base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toshihiro Umehara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This 'statsailr_procs_base' gem provides a collection of fundamental
|
14
14
|
PROCs for StatSailr program. This gem is essential for StatSailr to provide a useful
|