0
|
1 library("MatrixEQTL");
|
|
2
|
|
3 anova.groups = 5;
|
|
4 options(MatrixEQTL.ANOVA.categories = anova.groups);
|
|
5
|
|
6 # Number of columns (samples)
|
|
7 n = 100;
|
|
8 # Number of covariates
|
|
9 nc = 10;
|
|
10 # Generate the standard deviation of the noise
|
|
11 noise.std = 0.1 + rnorm(n)^2;
|
|
12 # Generate the covariates
|
|
13 cvrt.mat = 2 + matrix(rnorm(n*nc), ncol = nc);
|
|
14
|
|
15 # Generate the vectors with single genotype and expression variables
|
|
16 snps.mat = floor(runif(n, min = 0, max = anova.groups));
|
|
17 gene.mat = 1 + (snps.mat==1) + cvrt.mat %*% rnorm(nc) + rnorm(n) * noise.std;
|
|
18
|
|
19 # Create 3 SlicedData objects for the analysis
|
|
20 snps1 = SlicedData$new( matrix( snps.mat, nrow = 1 ) );
|
|
21 gene1 = SlicedData$new( matrix( gene.mat, nrow = 1 ) );
|
|
22 cvrt1 = SlicedData$new( t(cvrt.mat) );
|
|
23
|
|
24 # Produce no output files
|
|
25 filename = NULL; # tempfile()
|
|
26
|
|
27 # Call the main analysis function
|
|
28 me = Matrix_eQTL_main(
|
|
29 snps = snps1,
|
|
30 gene = gene1,
|
|
31 cvrt = cvrt1,
|
|
32 output_file_name = filename,
|
|
33 pvOutputThreshold = 1,
|
|
34 useModel = modelANOVA,
|
|
35 errorCovariance = diag(noise.std^2),
|
|
36 verbose = TRUE,
|
|
37 pvalue.hist = FALSE );
|
|
38
|
|
39 # Pull Matrix eQTL results - t-statistic and p-value
|
|
40
|
|
41 fstat = me$all$eqtls$statistic;
|
|
42 pvalue = me$all$eqtls$pvalue;
|
|
43 rez = c( Fstat = fstat, pvalue = pvalue);
|
|
44 # And compare to those from ANOVA in R
|
|
45 {
|
|
46 cat("\n\n Matrix eQTL: \n");
|
|
47 print(rez);
|
|
48 cat("\n R anova(lm()) output: \n");
|
|
49 lmdl = lm( gene.mat ~ cvrt.mat + factor(snps.mat),
|
|
50 weights = 1/noise.std^2 );
|
|
51 lmout = anova(lmdl)[2, c("F value","Pr(>F)")];
|
|
52 print( lmout );
|
|
53 }
|
|
54
|
|
55 # Results from Matrix eQTL and "lm" must agree
|
|
56 stopifnot(all.equal(lmout, rez, check.attributes=FALSE));
|