-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToy Data.R
78 lines (64 loc) · 2.18 KB
/
Toy Data.R
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Toy data for 00_MD2S.R functions.
library(matrixStats)
# Input datasets
# create X1 and y1 in main file.
X <- matrix(rnorm(100*4, 30, 23), nrow = 100, ncol = 4)
y <- matrix(rnorm(100*8, 22, 5), nrow = 100, ncol = 8)
# WHAT IS `make.int` FUNCTION DOING???
# SOLUTION: make.int() standardizes the columns & rows of the matrix:
# "we preprocess the matrices by double-centering them, so that the row-mean,
# column-mean, and grand mean is zero" (pg. 216 of paper)
# Check column means:
colMeans(X)
colMeans(make.int(X))
# Check row means:
head(rowMeans(X))
head(rowMeans(make.int(X)))
# Overall matrix mean:
mean(X)
mean(make.int(X))
# Check column sd:
colSds(X)
colSds(make.int(X)) # Now all columns have same std.
# Check row sd:
head(rowSds(X))
head(rowSds(make.int(X))) # Now all rows have same std.
# Overall matrix sd:
sd(X)
sd(make.int(X))
# Now check if column/row/grand means are zero:
colMeans(X1) # Basically zero.
head(rowMeans(X1)) # basically zero.
mean(X1) # Basically zero.
colMeans(y1) # Basically zero.
head(rowMeans(y1)) # basically zero.
mean(y1) # Basically zero.
# WHAT IS `my.norm` FUNCTION DOING?
# ANSWER: `my.norm` creates z-scores for every value of input.
test1 <- t(b0$z%*%X1)
my.norm <- function(x) {
x <- as.vector(x)
x <- x - mean(x)
(x / sum(x^2)^.5)
}
# Test with
# ------------------------------------------------------
# Load libraries and set working directory
# ------------------------------------------------------
library(devtools)
library(roxygen2)
# ------------------------------------------------------
# Set working directory
# ------------------------------------------------------
setwd("/Users/ysui/Documents/GitHub")
# ------------------------------------------------------
# load package
# ------------------------------------------------------
current.code <- as.package("md2s")
# Load all of the functions so you can use them
load_all(current.code, quiet = F)
document(current.code, quiet = F) # Make the help files
# ------------------------------------------------------
# Test functions
# ------------------------------------------------------
test1 <- md2sPermute(kX.num = 100, n = 50, ky = 40, nsims = 200, nperm = 200, nboot = 200)