-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gen_data.R
164 lines (142 loc) · 4.47 KB
/
Gen_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Function of Data Genetate
library(MASS)
library(LaplacesDemon)
#normal
library(LaplacesDemon)
Gen_data = function(n = 100, beta, Sigma0){
q = length(beta)
X = rnorm(n,0,1)
epsilon = rmvn(n, mu = rep(0,q), Sigma = Sigma0)
Y = X%*%t(beta) + epsilon
return(list(Y = matrix(Y,ncol = q), X = matrix(X,ncol = 1)))
}
#cauchy
Gen_data2 = function(n = 100, beta, S, COR){
library(LaplacesDemon)
q = length(beta)
X = rnorm(n)
epsiolon = rmvc(n, mu = rep(0,q), S = S)%*%Msq(COR,0.5)
Y = X%*%t(beta) + epsiolon
return(list(Y = matrix(Y,ncol = q), X = matrix(X,ncol = 1)))
}
#mixnormal
Gen_data3 = function(n = 100, beta, mu, Sigma1, Sigma2,ratio = 0.1){
library(LaplacesDemon)
q = as.numeric(ncol(Sigma1))
X = rnorm(n)
#epsilon = rmvn(n, mu = rep(0,q), Sigma = Sigma1)+rbind(matrix(rep(0,n*(1-ratio)*q),ncol=q),rmvn(n*ratio,mu,Sigma2))
#epsilon = 0.8*rmvn(n, mu = rep(0,q), Sigma = Sigma1)+0.2*rmvn(n, mu = mu, Sigma = Sigma2)
w = runif(n)
epsilon = matrix(rep(0,n*q),ncol = q)
for(j in 1:n){
if(w[j]<1-ratio){
epsilon[j,] = rmvn(1, mu = rep(0,q), Sigma = Sigma1)
}else{
epsilon[j,] = rmvn(1, mu = mu, Sigma = Sigma2)
}
}
Y = X%*%t(beta) + epsilon
return(list(Y = matrix(Y,ncol = q), X = matrix(X,ncol = 1)))
}
#Question heteroscedasticity
Gen_data4 = function(n = 100, beta, Sigma0){
library(LaplacesDemon)
q = as.numeric(ncol(Sigma0))
X = rnorm(n)
epsilon = rmvn(1, mu = rep(0,q), Sigma = (1+(X[1]^(2)))*Sigma0)
for(i in 2:n){
epsilon = rbind(epsilon, rmvn(1, mu = rep(0,q), Sigma = (1+(X[i]^(2)))*Sigma0))
}
Y = X%*%t(beta) + epsilon
return(list(Y = matrix(Y,ncol = q), X = matrix(X,ncol = 1)))
}
library(LaplacesDemon)
# real heteroscedasticity
Gen_data5 = function(n = 100, beta, Sigma0){
q = as.numeric(ncol(Sigma0))
X = rnorm(n)
epsilon = (diag(n)+1*diag(X))%*%rmvn(n, mu = rep(0,q), Sigma = Sigma0)
Y = X%*%t(beta) + epsilon
return(list(Y = matrix(Y,ncol = q), X = matrix(X,ncol = 1)))
}
#test for distribution of x
Gen_data6 = function(n = 100, beta, Sigma0){
q = length(beta)
#X = rnorm(n,5,1)
#X = rcauchy(n)
X = rnorm(n)
epsilon = rmvn(n, mu = rep(0,q), Sigma = Sigma0)
Y = X%*%t(beta) + epsilon
return(list(Y = matrix(Y,ncol = q), X = matrix(X,ncol = 1)))
}
#t distribution
Gen_data7 = function(n = 100, beta, Sigma0, df = Inf){
q = length(beta)
#X = rnorm(n,5,1)
#X = rcauchy(n)
X = rnorm(n)
epsilon = rmvt(n, mu = rep(0,q), S = Sigma0, df)
Y = X%*%t(beta) + epsilon
return(list(Y = matrix(Y,ncol = q), X = matrix(X,ncol = 1)))
}
#Multivarate laplace
Gen_data8 = function(n = 100, beta, Sigma0){
q = length(beta)
#X = rnorm(n,5,1)
#X = rcauchy(n)
X = rnorm(n)
epsilon = rmvl(n,mu = rep(0,q), Sigma = Sigma0)
Y = X%*%t(beta) + epsilon
return(list(Y = matrix(Y,ncol = q), X = matrix(X,ncol = 1)))
}
#Multivariate log-Normal
Gen_data9 = function(n = 100, beta, Sigma0){
q = length(beta)
#X = rnorm(n,5,1)
#X = rcauchy(n)
X = rnorm(n)
epsilon = exp(rmvn(n,mu = rep(0,q), Sigma = Sigma0))
Y = X%*%t(beta) + epsilon
return(list(Y = matrix(Y,ncol = q), X = matrix(X,ncol = 1)))
}
Gen_data9X = function(n = 100, beta, Sigma0){
q = length(beta)
#X = rnorm(n,5,1)
#X = rcauchy(n)
X = rnorm(n)
lep = exp(rnorm(n, 0, Sigma0))
for (j in 2:q){
lep = cbind(lep, exp(rnorm(n, 0, Sigma0)))
}
#epsilon = exp(rmvn(n,mu = rep(0,q), Sigma = Sigma0))
Y = X%*%t(beta) + lep
return(list(Y = matrix(Y,ncol = q), X = matrix(X,ncol = 1)))
}
#Gen_data9X(n=100, beta = c(1,0,1), Sigma0 = 2)
#g-h distribution
library(gk)
Gen_dataTgh = function(n = 100, beta, A, B, g=1, h=0.2){ #as the reviewer requested
q = length(beta)
#X = rnorm(n,5,1)
#X = rcauchy(n)
X = rnorm(n)
epsilon = matrix(rep(0, n*q), ncol = q)
for(j in 1:q){
epsilon[,j] = rgh(n, A, B, g=1, h=0.2, c = 0.8, type = "tukey")
}
Y = X%*%t(beta) + epsilon
return(list(Y = matrix(Y,ncol = q), X = matrix(X,ncol = 1)))
}
#Gen_dataTgh(n=100, beta=c(1,0,0), A=0,B=1)
Gen_dataGgh = function(n = 100, beta, A, B, g=1, h=0.2){ #as the reviewer requested
q = length(beta)
#X = rnorm(n,5,1)
#X = rcauchy(n)
X = rnorm(n)
epsilon = matrix(rep(0, n*q), ncol = q)
for(j in 1:q){
epsilon[,j] = rgh(n, A, B, g=1, h=0.2, c = 0.8, type = "generalised")
}
Y = X%*%t(beta) + epsilon
return(list(Y = matrix(Y,ncol = q), X = matrix(X,ncol = 1)))
}