-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdemo.R
69 lines (57 loc) · 1.67 KB
/
demo.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
library(rrBLUP)
train <- read.csv('data/protein.train.nan-101.csv')
test <- read.csv('data/protein.test.nan-101.csv')
train_x <- as.matrix(train[-1])
train_y <- as.matrix(train['label'])
test_x <- as.matrix(test[-1])
test_y <- as.matrix(test['label'])
# A.mat
start_time <- Sys.time()
Amat <- A.mat(train_x)
print(Amat)
print(Sys.time()-start_time)
# EM impute method
start_time <- Sys.time()
Amat <- A.mat(train_x, impute.method='EM')
print(Amat)
print(Sys.time()-start_time)
# mean impute method, return imputed
start_time <- Sys.time()
result <- A.mat(train_x, impute.method='mean', return.imputed=TRUE)
Amat <- result$A
train_x_imp <- result$imputed
print(Amat)
print(train_x_imp)
print(Sys.time()-start_time)
# EJ shrink method
start_time <- Sys.time()
Amat <- A.mat(train_x, shrink=TRUE)
print(Amat)
print(Sys.time()-start_time)
# REG shrink method
start_time <- Sys.time()
Amat <- A.mat(train_x, shrink=list(method="REG",n.qtl=100,n.iter=5))
print(Amat)
print(Sys.time()-start_time)
train <- read.csv('data/protein.train.csv')
test <- read.csv('data/protein.test.csv')
train_x <- as.matrix(train[-1])
train_y <- as.matrix(train['label'])
test_x <- as.matrix(test[-1])
test_y <- as.matrix(test['label'])
# mixed.solve using Matrix Z
start_time <- Sys.time()
result <- mixed.solve(y=train_y, Z=train_x)
print(result)
print(Sys.time()-start_time)
test_pred <- (test_x %*% as.matrix(result$u)) + as.vector(result$beta)
print(test_y)
print(test_pred)
# mixed.solve using Matrix K
start_time <- Sys.time()
result <- mixed.solve(y=train_y, K=A.mat(train_x))
print(result)
print(Sys.time()-start_time)
train_pred <- as.matrix(result$u) + as.vector(result$beta)
print(train_y)
print(train_pred)