simplex_project_mat: Create linear map to move simplex with p vertices to p-1...

Description Usage Arguments Value Examples

View source: R/containment-and-band-creation.R

Description

This approach comes for https://en.wikipedia.org/wiki/Simplex#Cartesian_coordinates_for_regular_n-dimensional_simplex_in_Rn and centers the projected points at 0.

Usage

1

Arguments

p

number of vertices

Value

A matrix that transforms each vertices (column) to (p-1) dimensional space

Examples

 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
31
32
A4 <- simplex_project_mat(4)
# expected for dim 4 (for examples on wikipedia)
A4_expected <- matrix(c(1,0,0,
                        -1/3, sqrt(8)/3,0,
                        -1/3,-sqrt(2)/3, sqrt(2/3),
                        -1/3, -sqrt(2)/3, -sqrt(2/3)),
                      ncol = 4)
all.equal(A4, A4_expected) # minor numerical inconsistencies

library(dplyr)

if (interactive()){
  # visualizing this 4d projection
  s4in3 <- simplex_project_mat(4) %>% t %>% data.frame %>%
    rbind(., data.frame(X1 = 0, X2 = 0, X3 = 0)) %>%
    mutate(color = factor(c(rep(1,4), 2)))#center


  library(plotly)
  plot_ly(s4in3,
          type = "scatter3d",
          mode = "markers", x = ~X1, y = ~X2, z = ~X3,
          color = ~color)
}
# visualizing a 3d projection
s3in2 <- simplex_project_mat(3) %>% t %>% data.frame %>%
 rbind(., data.frame(X1 = 0, X2 = 0)) %>%
 mutate(color = factor(c(rep(1,3), 2))) #center

library(ggplot2)
ggplot(s3in2) +
  geom_point(aes(x = X1, y = X2, color = color))

skgallagher/EpiCompare documentation built on Sept. 14, 2021, 5:45 a.m.