annotate MatrixEQTL/man/modelANOVA.Rd @ 4:cf4e9238644c draft default tip

Uploaded
author jasonxu
date Fri, 12 Mar 2021 08:23:32 +0000
parents cd4c8e4a4b5b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
1 \name{modelANOVA}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
2 \alias{modelANOVA}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
3 \docType{data}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
4 \title{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
5 Constant for \code{\link{Matrix_eQTL_engine}}.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
6 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
7 \description{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
8 Set parameter \code{useModel = modelANOVA} in the call of \code{\link{Matrix_eQTL_main}} to indicate that the genotype should be treated as a categorical variable.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
9 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
10 \note{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
11 By default, the number of ANOVA categories is fixed to be 3.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
12
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
13 To set it to a different number (say, 4) use the following command:
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
14
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
15 \code{options(MatrixEQTL.ANOVA.categories=4)}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
16
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
17 To check the current settings run:
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
18
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
19 \code{getOption('MatrixEQTL.ANOVA.categories', 3);}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
20 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
21 \examples{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
22 library('MatrixEQTL')
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
23
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
24 # Number of columns (samples)
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
25 n = 100;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
26
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
27 # Number of covariates
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
28 nc = 10;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
29
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
30 # Generate the standard deviation of the noise
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
31 noise.std = 0.1 + rnorm(n)^2;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
32
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
33 # Generate the covariates
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
34 cvrt.mat = 2 + matrix(rnorm(n*nc), ncol = nc);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
35
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
36 # Generate the vectors with single genotype and expression variables
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
37 snps.mat = floor(runif(n, min = 0, max = 3));
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
38 gene.mat = 1 + (snps.mat==1) + cvrt.mat \%*\% rnorm(nc) + rnorm(n) * noise.std;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
39
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
40 # Create 3 SlicedData objects for the analysis
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
41 snps1 = SlicedData$new( matrix( snps.mat, nrow = 1 ) );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
42 gene1 = SlicedData$new( matrix( gene.mat, nrow = 1 ) );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
43 cvrt1 = SlicedData$new( t(cvrt.mat) );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
44
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
45 # name of temporary output file
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
46 filename = tempfile();
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
47
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
48 snps1
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
49 gene1
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
50
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
51 # Call the main analysis function
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
52 me = Matrix_eQTL_main(
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
53 snps = snps1,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
54 gene = gene1,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
55 cvrt = cvrt1,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
56 output_file_name = filename,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
57 pvOutputThreshold = 1,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
58 useModel = modelANOVA,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
59 errorCovariance = diag(noise.std^2),
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
60 verbose = TRUE,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
61 pvalue.hist = FALSE );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
62 # remove the output file
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
63 unlink( filename );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
64
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
65 # Pull Matrix eQTL results - t-statistic and p-value
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
66
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
67 fstat = me$all$eqtls$statistic;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
68 pvalue = me$all$eqtls$pvalue;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
69 rez = c( Fstat = fstat, pvalue = pvalue)
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
70 # And compare to those from ANOVA in R
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
71 {
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
72 cat('\n\n Matrix eQTL: \n');
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
73 print(rez);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
74 cat('\n R anova(lm()) output: \n')
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
75 lmodel = lm( gene.mat ~ cvrt.mat + factor(snps.mat), weights = 1/noise.std^2 );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
76 lmout = anova( lmodel )[2, 4:5];
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
77 print( lmout )
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
78 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
79
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
80 # Results from Matrix eQTL and 'lm' must agree
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
81 stopifnot(all.equal(lmout, rez, check.attributes=FALSE))
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
82 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
83 \references{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
84 The package website: \url{http://www.bios.unc.edu/research/genomic_software/Matrix_eQTL/}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
85 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
86 \seealso{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
87 See \code{\link{Matrix_eQTL_engine}} for reference and sample code.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
88 }