annotate MatrixEQTL/man/modelLINEAR.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{modelLINEAR}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
2 \alias{modelLINEAR}
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} in the call of \code{\link{Matrix_eQTL_main}} to indicate that the effect of genotype on expression should be assumed to be additive linear.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
9 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
10
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
11 \examples{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
12 library('MatrixEQTL')
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
13
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
14 # Number of columns (samples)
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
15 n = 100;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
16
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
17 # Number of covariates
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
18 nc = 10;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
19
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
20 # Generate the standard deviation of the noise
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
21 noise.std = 0.1 + rnorm(n)^2;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
22
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
23 # Generate the covariates
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
24 cvrt.mat = 2 + matrix(rnorm(n*nc), ncol = nc);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
25
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
26 # Generate the vectors with genotype and expression variables
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
27 snps.mat = cvrt.mat \%*\% rnorm(nc) + rnorm(n);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
28 gene.mat = cvrt.mat \%*\% rnorm(nc) + rnorm(n) * noise.std + 0.5 * snps.mat + 1;
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,
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, weights = 1/noise.std^2 );
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
63 lmout = summary( lmodel )$coefficients[2, c(1,3,4)];
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
64 print( lmout )
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
65 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
66
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
67 # Results from Matrix eQTL and 'lm' must agree
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
68 stopifnot(all.equal(lmout, rez, check.attributes=FALSE))
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
69 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
70 \references{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
71 The package website: \url{http://www.bios.unc.edu/research/genomic_software/Matrix_eQTL/}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
72 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
73 \seealso{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
74 See \code{\link{Matrix_eQTL_engine}} for reference and sample code.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
75 }