Skip to contents

Create any projection matrix with a self-defined projection matrix function and projection optimization model function

Usage

RotMatMake(
  X = NULL,
  y = NULL,
  RotMatFun = "RotMatPPO",
  PPFun = "PPO",
  FunDir = getwd(),
  paramList = NULL,
  ...
)

Arguments

X

An n by d numeric matrix (preferable) or data frame.

y

A response vector of length n.

RotMatFun

A self-defined projection matrix function name, which can also be RotMatRand and RotMatPPO. Note that (,...) is necessary.

PPFun

A self-defined projection function name, which can also be PPO. Note that (,...) is necessary.

FunDir

The path to the function of the user-defined NodeRotateFun (default current Workspace).

paramList

List of parameters used by the functions RotMatFun and PPFun. If left unchanged, default values will be used, for details see defaults.

...

Used to handle superfluous arguments passed in using paramList.

Value

A random matrix to use in running ODT.

  • Variable: Variables to be projected.

  • Number: Number of projections.

  • Coefficient: Coefficients of the projection matrix.

Details

There are two ways for the user to define a projection direction function. The first way is to connect two custom functions with the function RotMatMake(). Specifically, RotMatFun() is defined to determine the variables to be projected, the projection dimensions and the number of projections (the first two columns of the rotation matrix). PPFun() is defined to determine the projection coefficients (the third column of the rotation matrix). After that let the argument RotMatFun="RotMatMake", and the argument paramList must contain the parameters RotMatFun and PPFun. The second way is to define a function directly, and just let the argument RotMatFun be the name of the defined function and let the argument paramList be the arguments list used in the defined function.

Examples

set.seed(220828)
X <- matrix(rnorm(1000), 100, 10)
y <- (rnorm(100) > 0) + 0
(RotMat <- RotMatMake(X, y, "RotMatRand", "PPO"))
#>       Variable Number Coefficient
#>  [1,]        7      1  1.00000000
#>  [2,]        1      2  0.57384117
#>  [3,]        3      2  0.11546398
#>  [4,]        4      2  0.38222074
#>  [5,]        6      2  0.71503964
#>  [6,]        5      3  0.26515379
#>  [7,]        6      3  0.65980321
#>  [8,]       10      3 -0.70310255
#>  [9,]        5      4  0.27464916
#> [10,]        7      4 -0.02355140
#> [11,]        8      4 -0.96087481
#> [12,]        9      4  0.02706962
library(nnet)
(RotMat <- RotMatMake(X, y, "RotMatPPO", "PPO", paramList = list(model = "Log")))
#>       Variable Number Coefficient
#>  [1,]       10      1   1.0000000
#>  [2,]        5      2   1.0000000
#>  [3,]        3      3   1.0000000
#>  [4,]        2      4   1.0000000
#>  [5,]        4      5   3.4905900
#>  [6,]        1      5  -6.6609352
#>  [7,]       10      5   4.2280817
#>  [8,]        7      5  -6.4552493
#>  [9,]        6      5   4.5486872
#> [10,]        8      6 -16.5737922
#> [11,]        3      6 -23.3417386
#> [12,]        5      6  12.5920425
#> [13,]        2      6  12.6463337
#> [14,]        9      6  60.5034813
#> [15,]        8      7  -2.5041262
#> [16,]        9      7  -0.1602014
#> [17,]       10      7   1.1502737
#> [18,]        6      7   1.2121139
#> [19,]        1      7   0.2975510

## Define projection matrix function makeRotMat and projection pursuit function makePP.##
##  Note that '...' is necessary.
makeRotMat <- function(dimX, dimProj, numProj, ...) {
  RotMat <- matrix(1, dimProj * numProj, 3)
  for (np in seq(numProj)) {
    RotMat[(dimProj * (np - 1) + 1):(dimProj * np), 1] <-
      sample(1:dimX, dimProj, replace = FALSE)
    RotMat[(dimProj * (np - 1) + 1):(dimProj * np), 2] <- np
  }
  return(RotMat)
}

makePP <- function(dimProj, prob, ...) {
  pp <- sample(c(1L, -1L), dimProj, replace = TRUE, prob = c(prob, 1 - prob))
  return(pp)
}
# \donttest{
RotMat <- RotMatMake(
  RotMatFun = "makeRotMat", PPFun = "makePP",
  paramList = list(dimX = 8, dimProj = 5, numProj = 4, prob = 0.5)
)
#> Warning: cannot open file '/home/runner/work/ODRF/ODRF/docs/reference/makeRotMat.R': No such file or directory
#> Error in file(filename, "r", encoding = encoding): cannot open the connection
head(RotMat)
#>      Variable Number Coefficient
#> [1,]       10      1    1.000000
#> [2,]        5      2    1.000000
#> [3,]        3      3    1.000000
#> [4,]        2      4    1.000000
#> [5,]        4      5    3.490590
#> [6,]        1      5   -6.660935
#>      Variable Number Coefficient
#> [1,]        6      1           1
#> [2,]        8      1           1
#> [3,]        1      1          -1
#> [4,]        4      1          -1
#> [5,]        5      1          -1
#> [6,]        6      2           1
# }
# \donttest{
# train ODT with defined projection matrix function
tree <- ODT(X, y,
  split = "entropy", NodeRotateFun = "makeRotMat",
  paramList = list(dimX = ncol(X), dimProj = 5, numProj = 4)
)
#> Warning: cannot open file '/home/runner/work/ODRF/ODRF/docs/reference/makeRotMat.R': No such file or directory
#> Error in file(filename, "r", encoding = encoding): cannot open the connection
# train ODT with defined projection matrix function and projection optimization model function
tree <- ODT(X, y,
  split = "entropy", NodeRotateFun = "RotMatMake", paramList =
    list(
      RotMatFun = "makeRotMat", PPFun = "makePP",
      dimX = ncol(X), dimProj = 5, numProj = 4, prob = 0.5
    )
)
#> Warning: cannot open file '/home/runner/work/ODRF/ODRF/docs/reference/makeRotMat.R': No such file or directory
#> Error in file(filename, "r", encoding = encoding): cannot open the connection
# }