comparison MatrixEQTL/demo/a.nocvrt.r @ 0:cd4c8e4a4b5b draft

Uploaded
author jasonxu
date Fri, 12 Mar 2021 08:12:46 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:cd4c8e4a4b5b
1 library("MatrixEQTL");
2
3 # Number of columns (samples)
4 n = 100;
5
6
7
8
9
10
11
12
13
14
15 # Generate the vectors with genotype and expression variables
16 snps.mat = rnorm(n);
17 gene.mat = rnorm(n) + 0.5 * snps.mat;
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();
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 = modelLINEAR,
35 errorCovariance = numeric(),
36 verbose = TRUE,
37 pvalue.hist = FALSE );
38
39 # Pull Matrix eQTL results - t-statistic and p-value
40 beta = me$all$eqtls$beta;
41 tstat = me$all$eqtls$statistic;
42 pvalue = me$all$eqtls$pvalue;
43 rez = c(beta = beta, tstat = tstat, pvalue = pvalue);
44 # And compare to those from the linear regression in R
45 {
46 cat("\n\n Matrix eQTL: \n");
47 print(rez);
48 cat("\n R summary(lm()) output: \n");
49 lmdl = lm( gene.mat ~ snps.mat );
50
51 lmout = summary(lmdl)$coefficients[2,c("Estimate","t value","Pr(>|t|)")];
52 print( lmout );
53 }
54
55 # Results from Matrix eQTL and "lm" must agree
56 stopifnot(all.equal(lmout, rez, check.attributes=FALSE));