Some Algoritms for Mixed Models

Share:

Description

The LMM model of focus can be expressed as

Y=XB+∑_{j=1}^k Z_j G_j+WE,

where Y is the n \times d response variable, X is the n \times q design matrix of q \times d the fixed effects B, Z_j for j=1,2,…,k (k≥q 1) are the n \times q_j design matrices of the q_j \times d random effects G_j, and W is the n \times t design matrix of t \times d residual effecs E. The random effects and the residual are independently distributed, and have matrix variate distributions (G_j\sim N_{q_j \times d}(0_{q_j \times d}, K_j,Σ_j) for j=1,2,…,k and E\sim N_{t \times d}(0_{t \times d}, R,Σ_E)). The matrices K_j, R, Σ_j, Σ_E might be further parametrized. When the response is univariate (d=1) there is no need to specify a structure for Σ_j's andΣ_E. On the other hand, the K_j and R are concordance matrices (covariance matrices with some standardization over the diagonals) and they need to be provided by the user.

Please refer to the examples below and the other help files for more details about the concordance and covariance structures.

!!IMPORTANT NOTE!!: USE SAMM WITH CAUTION, AND AT YOUR OWN RISK! NO GUARANTIES, NO CLAIMS.

PLEASE REPORT BUGS AND RECOMMENDATIONS TO THE MAINTAINER.

Usage

1
2
SAMM(Y,X,Zlist,Klist, lambda, W,R,Siglist, corfunc, corfuncfixed,  sigfunc,
mmalg, tolparconv=1e-10, tolparinv=1e-10,maxiter=1000, geterrors=FALSE, Hinv = FALSE)

Arguments

Y

Y is the n \times d response variable

X

n \times q design matrix of q \times d the fixed effects B

Zlist

a list object containing Z_j for j=1,2,…,k (k≥q 1), the n \times q_j design matrices of the q_j \times d random effects G_j,

Klist

a list to specify the concordance matrices K_j for j=1,2,…,k. For each j, the user needs to provide a constant matrix, or a list specifying the concordance structure

lambda

a scalar shrinkage parameter for shrinkage of variance components (only works with the choice mmalg=”mmmk_ml”).

W

W is the n \times t design matrix of t \times d residual effecs E

R

a list to specify the concordance matrix R,the user needs to provide a constant matrix, or a list specifying the concordance structure

Siglist

a list to specify the covariance structures Σ_j's andΣ_E

corfunc

a boolian vector specifying whether K_j for j=1,2,…,k and R are functions or given matrices (TRUE for functions)

corfuncfixed

a boolian vector specifying whether K_j for j=1,2,…,k and R are fixed at the initial parameter values specified

sigfunc

a boolian vector specifying whether Σ_j for j=1,2,…,k, E are functions or unstructured (TRUE for functions)

mmalg

The mixed model solving algorithm

tolparconv

convergence number

tolparinv

a small scalar to add to the diagonals of positive semidefinite matrices for inversion or for calculating the Cholesky decompositions

maxiter

Maximum number of iterations

geterrors

TRUE or FALSE, if true prediction error variances for the random effects are supplied in the output

Hinv

TRUE or FALSE, if true inverse of H matrix will be returned

Details

The algorithms in SAMM were mostly concieved based on the ideas in the referenced papers: 1-emm_reml: reference 4. 2-emm_ml: reference 4. 3-dmm_ml: reference 1. 4-dmm_reml: reference 1. 5-dermm_reml1: reference 5 (Fisher-Scoring). 6-dermm_reml2: reference 5 (Average Information). 7-mm_ml: reference 2. 8-emmmk_reml: reference 4. 9-emmmk_ml: reference 4. 10-mmmk_ml: reference 2. 11-emmmv_ml: reference 4. 12-mmmv_ml: reference 3. 13-mmmkmv_ml: reference 2. The table below shows which cases these algorithms can be used. The prefered algorithms are marked by paranthesis and the user still needs to specify it.

No Univariate One K corfunc sigfunc shrinkage WRWtIdent ALGS
1- + + - 0 - + 1-12 (1)
2- + + - 0 - - 3-7, 10-12 (3)
3- + + 1^* 0 0 0 3-6, 10-11 (3)
4- + + + 0 0 0 10, 13 (10)
5- + - - 0 - + 5, 6, 8, 9, 10, 13 (5)
6- + - - 0 - - 5, 6, 10, 13 (5)
7- + - + 0 - - 5, 6, 10, 13 (5)
8- + - - 0 + 0 10 (10)
9- + - + 0 + 0 10 (10)
10- - + - - - - 11, 12 (11)
11- - + - - - - 12 (12)
12- - - - - - 0 13 (13)
13- - - 2^* 2^* - 0 13 (13)
14- - + 2^* 2^* - 0 13 (13)

-: No. +: Yes. 0: Doesn't matter. 1^*: Only K is a function not R. 2^*: sigmafunc or corfunc.

Value

A named list object (the output will differ for different algorithms and model types!).

Author(s)

Deniz Akdemir

References

1-Bates, Douglas M. "lme4: Mixed-effects modeling with R." URL http://lme4. r-forge. r-project. org/book (2010).

2-Zhou, Hua, et al. "MM Algorithms for Variance Components Models." arXiv preprint arXiv:1509.07426 (2015).

3-Zhou, Xiang, and Matthew Stephens. "Efficient algorithms for multivariate linear mixed models in genome-wide association studies." Nature methods 11.4 (2014): 407.

4-Kang, Hyun Min, et al. "Efficient control of population structure in model organism association mapping." Genetics 178.3 (2008): 1709-1723.

5-Gilmour, Arthur R., Robin Thompson, and Brian R. Cullis. "Average information REML: an efficient algorithm for variance parameter estimation in linear mixed models." Biometrics (1995): 1440-1450.

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
 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
## Not run: 
library(SAMM)
#set.seed(12345)

n=120
ntrain=100
M1<-matrix(rbinom(n*180,2,.3)-1, nrow=n)
K<-relmatcov_cppforR(c(0), M1)
K[1:5,1:5]
det(K)
K=K+1e-3*diag(n)
mean(diag(K))

covY<-2*K+1*diag(n)

Y<-10+crossprod(chol(covY),rnorm(n))


#training set
Trainset<-sample(1:n,ntrain,replace=(ntrain>n))
y=Y[Trainset]
X=matrix(rep(1, n)[Trainset], ncol=1)
Z=diag(n)[Trainset,]




########1
samout1<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z), Klist=list(K),
lambda=0, W=diag(ntrain),R=list(diag(ntrain)),Siglist=list(),
corfunc=c(F,F), corfuncfixed=c(F,F), sigfunc=c(F),mmalg="emm_ml",
tolparconv=1e-10, tolparinv=1e-10,maxiter=1000,geterrors=F)

samout2<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z), Klist=list(K),
lambda=0, W=diag(ntrain),R=list(diag(ntrain)),Siglist=list(),
corfunc=c(F,F), corfuncfixed=c(F,F), sigfunc=c(F),mmalg="emm_reml",
tolparconv=1e-10, tolparinv=1e-10,maxiter=1000,geterrors=F)

samout3<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z),
Klist=list(list("Const",c(0),K)), lambda=0, 
W=diag(ntrain),R=list(diag(ntrain)),Siglist=list(),
corfunc=c(F,F), corfuncfixed=c(F,F), sigfunc=c(F),
mmalg="dmm_ml", tolparconv=1e-10, tolparinv=1e-10,
maxiter=1000,geterrors=F)

samout4<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z), 
Klist=list(list("Const",c(0),K)), lambda=0, 
W=diag(ntrain),R=list(diag(ntrain)),Siglist=list(), 
corfunc=c(F,F), corfuncfixed=c(F,F), sigfunc=c(F),
mmalg="dmm_reml", tolparconv=1e-10, tolparinv=1e-10,
maxiter=1000,geterrors=F)

samout5<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z),
Klist=list(K), lambda=0, W=diag(ntrain),
R=list(diag(ntrain)),Siglist=list(), corfunc=c(F,F), 
corfuncfixed=c(F,F), sigfunc=c(F),mmalg="mm_ml", 
tolparconv=1e-10, tolparinv=1e-10,maxiter=1000,geterrors=F)

samout6<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z), 
Klist=list(K), lambda=0, W=diag(ntrain),R=list(diag(ntrain)),
Siglist=list(), corfunc=c(F,F), corfuncfixed=c(F,F), 
sigfunc=c(F),mmalg="dermm_reml1", tolparconv=1e-10, 
tolparinv=1e-10,maxiter=1000,geterrors=F)

samout7<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z),
Klist=list(K), lambda=0, W=diag(ntrain),R=list(diag(ntrain)),
Siglist=list(), corfunc=c(F,F), corfuncfixed=c(F,F), 
sigfunc=c(F),mmalg="dermm_reml2", tolparconv=1e-10, 
tolparinv=1e-10,maxiter=1000,geterrors=F)

samout8<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z),
Klist=list(K), lambda=0, W=diag(ntrain),R=list(diag(ntrain)),
Siglist=list(), corfunc=c(F,F), corfuncfixed=c(F,F), 
sigfunc=c(F),mmalg="mmmk_ml", tolparconv=1e-10, 
tolparinv=1e-10,maxiter=1000,geterrors=F)

samout9<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z), 
Klist=list(K), lambda=0, W=diag(ntrain),R=list(diag(ntrain)),
Siglist=list(), corfunc=c(F,F), corfuncfixed=c(F,F), 
sigfunc=c(F),mmalg="emmmk_reml", tolparconv=1e-10, 
tolparinv=1e-10,maxiter=1000,geterrors=F)

samout10<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z), 
Klist=list(K), lambda=0, W=diag(ntrain),R=list(diag(ntrain)),
Siglist=list(), corfunc=c(F,F), corfuncfixed=c(F,F), 
sigfunc=c(F),mmalg="emmmk_ml", tolparconv=1e-10, 
tolparinv=1e-10,maxiter=1000,geterrors=F)

samout11<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z),
Klist=list(K), lambda=0, W=diag(ntrain),R=list(diag(ntrain)),
Siglist=list(), corfunc=c(F,F), corfuncfixed=c(F,F), sigfunc=c(F),
mmalg="emmmv_ml", tolparconv=1e-10, tolparinv=1e-10,maxiter=1000,geterrors=F)

###########2
R<-diag(ntrain)
diag(R)<-diag(R)+.01*rnorm(nrow(R))

samout12<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z),
Klist=list(K), lambda=0, W=diag(ntrain),R=list(R),
Siglist=list(), corfunc=c(F,F), corfuncfixed=c(F,F),
sigfunc=c(F),mmalg="mmmk_ml", tolparconv=1e-10, 
tolparinv=1e-10,maxiter=1000,geterrors=F)

samout13<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z), 
Klist=list(K), lambda=0, W=diag(ntrain),R=list(R),
Siglist=list(), corfunc=c(F,F), corfuncfixed=c(F,F), 
sigfunc=c(F),mmalg="mm_ml", tolparconv=1e-10, 
tolparinv=1e-10,maxiter=1000,geterrors=F)

samout14<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z),
Klist=list(K), lambda=0, W=diag(ntrain),R=list(R),
Siglist=list(), corfunc=c(F,F), corfuncfixed=c(F,F), 
sigfunc=c(F),mmalg="mmmv_ml", tolparconv=1e-10, 
tolparinv=1e-10,maxiter=1000,geterrors=F)

samout15<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z), 
Klist=list(K), lambda=0, W=diag(ntrain),R=list(R),
Siglist=list(), corfunc=c(F,F), corfuncfixed=c(F,F), 
sigfunc=c(F),mmalg="mmmkmv_ml", tolparconv=1e-10, 
tolparinv=1e-10,maxiter=1000,geterrors=F)

samout16<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z), 
Klist=list(K), lambda=0, W=diag(ntrain),R=list(R),Siglist=list(),
corfunc=c(F,F), corfuncfixed=c(F,F), sigfunc=c(F),
mmalg="dermm_reml1", tolparconv=1e-10,
tolparinv=1e-10,maxiter=1000,geterrors=F)

samout17<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z), 
Klist=list(K), lambda=0, W=diag(ntrain),R=list(R),
Siglist=list(), corfunc=c(F,F), corfuncfixed=c(F,F),
sigfunc=c(F),mmalg="dermm_reml2", tolparconv=1e-10, 
tolparinv=1e-10,maxiter=1000,geterrors=F)

samout18<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z),
Klist=list(list("Const",c(0),K)), lambda=0, W=diag(ntrain),
R=list(R),Siglist=list(), corfunc=c(F,F), 
corfuncfixed=c(F,F), sigfunc=c(F),mmalg="dmm_ml",
tolparconv=1e-10, tolparinv=1e-10,maxiter=1000,geterrors=F)

samout19<-SAMM(Y=matrix(y,ncol=1),X=X, Zlist=list(Z), 
Klist=list(list("Const",c(0),K)), lambda=0, W=diag(ntrain),
R=list(R),Siglist=list(), corfunc=c(F,F), corfuncfixed=c(F,F), 
sigfunc=c(F),mmalg="dmm_reml", tolparconv=1e-10,
tolparinv=1e-10,maxiter=1000,geterrors=F)



samout1$Vu
samout2$Vu
samout3$Vu
samout4$Vu
samout5$Vu
samout6$Vu
samout7$Vu
samout8$Vu
samout9$Vu
samout10$Vu
samout11$Vgt

samout12$Vu
samout13$Vu
samout14$sigmahatlist[[1]]
samout15$sigmahatlist[[1]]
samout16$Vu
samout17$Vu
samout18$Vu
samout19$Vu





###############################

library(SAMM)
n=100
nsample=80
rhotrans=5
ar1cov_cppforR(c(rhotrans),matrix(5))
rho=(2/pi)*atan(rhotrans)
rho
tan((pi/2)*(rho))

M1<-matrix(rbinom(n*300, 2, .2)-1, nrow=n)
K1<-relmatcov_cppforR(c(.01), M1)

M2<-matrix(rbinom(n*300, 2, .2)-1, nrow=n)
K2<-relmatcov_cppforR(c(0.03), M2)
W=(diag(5)[sample(1:5,n, replace=TRUE),])
covY<-3*K1+5*K2+10*(W%*%ar1cov_cppforR(c(rhotrans),matrix(5))%*%t(W))
K1[1:5,1:5]
dim(W)
dim(ar1cov_cppforR(c(6),matrix(5)))
Y<-10+crossprod(chol(covY),rnorm(n))


#training set
Trainset<-sample(1:n,nsample)
ytrain=Y[Trainset]
Xtrain=matrix(rep(1, n)[Trainset], ncol=1)
Ztrain=diag(n)[Trainset,]
Wtrain=W[Trainset,]


samout27<-SAMM(Y=matrix(ytrain,ncol=1),X=Xtrain,
Zlist=list(Ztrain, Ztrain), Klist=list(K1,K2), 
lambda=0, W=Wtrain,R=list(list("ar1",c(0),matrix(5,1,1))),
Siglist=list("","",""), corfunc=c(F,F,T), 
corfuncfixed=c(F,F,F), sigfunc=c(F,F,F),mmalg="mmmk_ml",
tolparconv=1e-10, tolparinv=1e-10,maxiter=1000,geterrors=F)
str(samout27)

samout28<-SAMM(Y=matrix(ytrain,ncol=1),X=Xtrain,
Zlist=list(Ztrain, Ztrain), Klist=list(K1,K2), lambda=0, 
W=Wtrain,R=list(list("ar1",c(0),matrix(5,1,1))),Siglist=list("","",""),
corfunc=c(F,F,T), corfuncfixed=c(F,F,F), sigfunc=c(F,F,F),
mmalg="mmmkmv_ml", tolparconv=1e-10, tolparinv=1e-10,
maxiter=1000,geterrors=F)
str(samout28)

samout29<-SAMM(Y=matrix(ytrain,ncol=1),X=Xtrain,
Zlist=list(Ztrain, Ztrain), Klist=list(K1,K2),
lambda=0, W=Wtrain,R=list("ar1",c(0),matrix(5,1,1)),
Siglist=list("","",""), corfunc=c(F,F,T),
corfuncfixed=c(F,F,F), sigfunc=c(F,F,F),
mmalg="dermm_reml1", tolparconv=1e-10,
tolparinv=1e-10,maxiter=1000,geterrors=F)

str(samout29)

samout30<-SAMM(Y=matrix(ytrain,ncol=1),X=Xtrain,
Zlist=list(Ztrain, Ztrain), Klist=list(K1,K2),
lambda=0, W=Wtrain,R=list("ar1",c(0),matrix(5,1,1)),
Siglist=list("","",""), corfunc=c(F,F,T), corfuncfixed=c(F,F,F),
sigfunc=c(F,F,F),mmalg="dermm_reml2", tolparconv=1e-10,
tolparinv=1e-10,maxiter=1000,geterrors=F)
str(samout30)


###########################

###Data:



n=100
nsample=90

M1<-matrix(rbinom(n*300, 2, .2)-1, nrow=n)
K1<-relmatcov_cppforR(c(.1), M1)
Sigma1=ar1cov_cppforR(c(5),matrix(3))
Sigma2=ar1cov_cppforR(c(-2),matrix(3))
W=(diag(5)[sample(1:5,n, replace=T),])
K2=(W%*%ar1cov_cppforR(c(-3),matrix(5))%*%t(W))

covY<-5*kronecker(Sigma1,K1)+10*kronecker(Sigma2,K2)

Y<-10+crossprod(chol(covY),rnorm(n*3))
Y<-matrix(Y, ncol=3)


samout31<-SAMM(Y=Y,X=matrix(1,n,1), Zlist=list(diag(n)),
Klist=list(K1), lambda=0, W=W,R=list(list("ar1",c(0),matrix(5,1,1))),
Siglist=list("",""), corfunc=c(F,T), corfuncfixed=c(F,F), sigfunc=c(F,F),
mmalg="mmmkmv_ml", tolparconv=1e-10,
tolparinv=1e-10,maxiter=1000,geterrors=F)
str(samout31)

samout32<-SAMM(Y=Y,X=matrix(1,n,1), Zlist=list(diag(n)),
Klist=list(K1), lambda=0, W=W,R=list(list("ar1",c(0),matrix(5,1,1))),
Siglist=list("",list("diag",c(0,0,0),matrix(3,1,1))),
corfunc=c(F,T), corfuncfixed=c(F,F), 
sigfunc=c(F,T),mmalg="mmmkmv_ml", tolparconv=1e-10,
tolparinv=1e-10,maxiter=1000,geterrors=F)
str(samout32)

samout33<-SAMM(Y=Y,X=matrix(1,n,1), Zlist=list(diag(n)),
Klist=list(K1), lambda=0, W=W,R=list(list("ar1",c(0),matrix(5,1,1))),
Siglist=list("",list("Ident",c(0),matrix(3,1,1))), corfunc=c(F,T),
corfuncfixed=c(F,F), sigfunc=c(F,T),mmalg="mmmkmv_ml",
tolparconv=1e-10, tolparinv=1e-10,maxiter=1000,geterrors=F)
str(samout33)



###########################


n=100
M1<-matrix(rbinom(n*150, 2, .2)-1, nrow=n)
K1<-relmatcov_cppforR(c(0), M1)
M2<-matrix(rbinom(n*150, 2, .2)-1, nrow=n)
K2<-relmatcov_cppforR(c(0), M2)
M3<-matrix(rbinom(n*100, 2, .2)-1, nrow=n)
K3<-relmatcov_cppforR(c(0), M3)
M4<-matrix(rbinom(n*100, 2, .2)-1, nrow=n)
K4<-relmatcov_cppforR(c(0), M4)


covY<-2*K1+3*K2+1*K3+2*K4+3*diag(n)

Y<-10+crossprod(chol(covY),rnorm(n))


#training set
Trainset<-sample(1:n,80)
y=Y[Trainset]
X=matrix(rep(1, n)[Trainset], ncol=1)
Z=diag(n)[Trainset,]

X=X
y=y

samout35<-SAMM(Y=matrix(y,ncol=1),X=X,Zlist=list(Z,Z,Z,Z),
lambda=0,Klist=list(K1,K2,K3,K4), W=Z,R=list(diag(n)),
Siglist=list("","","","",""), corfunc=c(F,F,F,F,F), 
corfuncfixed=c(T,T,T,T,T),sigfunc=c(F,F,F,F,F),
mmalg="mmmk_ml", tolparconv=1e-10,
tolparinv=1e-10,maxiter=1000,geterrors=F)
str(samout35)

samout36<-SAMM(Y=matrix(y,ncol=1),X=X,Zlist=list(Z,Z,Z,Z),
lambda=0.99999,Klist=list(K1,K2,K3,K4), W=Z,
R=list(diag(n)),Siglist=list("","","","",""),
corfunc=c(F,F,F,F,F), corfuncfixed=c(T,T,T,T,T),
sigfunc=c(F,F,F,F,F),mmalg="mmmk_ml", tolparconv=1e-10,
tolparinv=1e-10,maxiter=1000,geterrors=F)
str(samout36)


outmat<-c()
for (lambda in seq(0,.999999, length=30)){
  samout37<-SAMM(Y=matrix(y,ncol=1),X=X,
  Zlist=list(Z,Z,Z,Z),lambda=lambda,Klist=list(K1,K2,K3,K4),
  W=Z,R=list(diag(n)),Siglist=list("","","","",""),
  corfunc=c(F,F,F,F,F), corfuncfixed=c(T,T,T,T,T), 
  sigfunc=c(F,F,F,F,F),mmalg="mmmk_ml",
  tolparconv=1e-10, tolparinv=1e-10,
  maxiter=1000,geterrors=F)
  outmat<-cbind(outmat,c(samout37$Vu*samout37$weights, samout37$Ve))
}
str(samout37)
colnames(outmat)<-seq(0,.999999, length=30)

maxmat<-max(c(outmat))
minmat<-min(c(outmat))

plot(seq(0,.999999, length=30),outmat[1,],
ylim=c(minmat-1, maxmat+1), col=2, type="b")
for (i in 2:5){
  par(new=T)
  plot(seq(0,.999999, length=30), outmat[i,],
  axes=F, ylim=c(minmat-1, maxmat+1), col=i+1, type="b", xlab="", ylab="")
}

## End(Not run)