annotate MatrixEQTL/man/modelLINEAR_CROSS.Rd @ 0:cd4c8e4a4b5b draft

Uploaded
author jasonxu
date Fri, 12 Mar 2021 08:12:46 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
1 \name{modelLINEAR_CROSS}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
2 \alias{modelLINEAR_CROSS}
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 = modelLINEAR_CROSS} in the call of \code{\link{Matrix_eQTL_main}} to indicate that Matrix eQTL should include the interaction of SNP and last covariate in the model and test for its significance.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
9 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
10 \examples{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
11 library('MatrixEQTL')
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
12
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
13 # Number of columns (samples)
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
14 n = 25;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
15
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
16 # Number of covariates
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
17 nc = 10;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
18
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
19 # Generate the standard deviation of the noise
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
20 noise.std = 0.1 + rnorm(n)^2;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
21
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
22 # Generate the covariates
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
23 cvrt.mat = 2 + matrix(rnorm(n*nc), ncol = nc);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
24
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
25 # Generate the vectors with single genotype and expression variables
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
26 snps.mat = cvrt.mat \%*\% rnorm(nc) + rnorm(n);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
27 gene.mat = cvrt.mat \%*\% rnorm(nc) + rnorm(n) * noise.std +
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
28 1 + 0.5 * snps.mat + snps.mat * cvrt.mat[,nc];
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
29
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
30 # Create 3 SlicedData objects for the analysis
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
31 snps1 = SlicedData$new( matrix( snps.mat, nrow = 1 ) );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
32 gene1 = SlicedData$new( matrix( gene.mat, nrow = 1 ) );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
33 cvrt1 = SlicedData$new( t(cvrt.mat) );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
34
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
35 # name of temporary output file
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
36 filename = tempfile();
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
37
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
38 # Call the main analysis function
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
39 me = Matrix_eQTL_main(
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
40 snps = snps1,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
41 gene = gene1,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
42 cvrt = cvrt1,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
43 output_file_name = filename,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
44 pvOutputThreshold = 1,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
45 useModel = modelLINEAR_CROSS,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
46 errorCovariance = diag(noise.std^2),
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
47 verbose = TRUE,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
48 pvalue.hist = FALSE );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
49 # remove the output file
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
50 unlink( filename );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
51
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
52 # Pull Matrix eQTL results - t-statistic and p-value
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
53 beta = me$all$eqtls$beta;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
54 tstat = me$all$eqtls$statistic;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
55 pvalue = me$all$eqtls$pvalue;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
56 rez = c(beta = beta, tstat = tstat, pvalue = pvalue)
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
57 # And compare to those from the linear regression in R
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
58 {
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
59 cat('\n\n Matrix eQTL: \n');
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
60 print(rez);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
61 cat('\n R summary(lm()) output: \n')
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
62 lmodel = lm( gene.mat ~ snps.mat + cvrt.mat + snps.mat*cvrt.mat[,nc],
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
63 weights = 1/noise.std^2 );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
64 lmout = tail(summary( lmodel )$coefficients,1)[,c(1,3,4)];
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
65 print( tail(lmout) );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
66 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
67
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
68 # Results from Matrix eQTL and 'lm' must agree
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
69 stopifnot(all.equal(lmout, rez, check.attributes=FALSE))
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
70 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
71 \references{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
72 The package website: \url{http://www.bios.unc.edu/research/genomic_software/Matrix_eQTL/}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
73 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
74 \seealso{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
75 See \code{\link{Matrix_eQTL_engine}} for reference and sample code.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
76 }