rtlb: ~ Function: R to LaTeX, Bivariate analysis ~

Description Usage Arguments Details Value Classical usage Author References See Also Examples

Description

r2latexBiv (r2lb in short) performs some bivariate analyses, then generates code to be included in a LaTeX document in order to print out the analyses in a (so nice!) LaTeX way.

Usage

1
2
  r2lb(formula,fileOut="",textBefore="",textAfter="",graphDir="graphBiv",graphName="V",type="png",displayStyle=7,limDiscreteY=10,limDiscreteX=10)
  r2latexBiv(formula,fileOut="",textBefore="",textAfter="",graphDir="graphBiv",graphName="V",type="png",displayStyle=7,limDiscreteY=10,limDiscreteX=10)

Arguments

formula

[variable~variable] or [variable~data.frame] : contains the data to analyse. In all the following, the left part will be called Y, the right part will be X.

fileOut

[character] name of the output file in which the LaTeX summary will be saved. If empty, the LaTeX code is printed on screen.

textBefore

[character] or [vector(character)] : before printing a variable analysis, r2lb can write a text. If X is a single variable, textBefore should be of length 1. If X is a data.frame, textBefore can have same length as the number of columns of the data.frame (this lets the user write a specific introduction for each variable), or can be of length 1. In this case, it is recycled. See examples for details.

textAfter

[character] or [vector(character)] : same as textBefore but the text is printed after the variable analysis. See textBefore and examples for details.

graphDir

[character] : directory used to save the graphs generated by the analyses.

graphName

[character] or [vector(character)] : prefix for the graph names. If empty, the graph names are V1 to V'length(data.frame)'

type

[character] : type of plotting device used to export the graphics. Can be Windows metafile, PNG, JPEG, BMP (Windows bitmap format), TIFF, PostScript or PDF.

displayStyle

[numeric] or [vector(numeric)] : r2lb proposes two different ways of displaying the results.

The first one is compact, it displays all the results on two lines. If the number of modalities of X is too big, this method could draw tables that outfit the page. In this case, a second display (on three lines, less compact but higher) is used.

The switch (compact/expanded) is done automatically by r2lb according to the number of modalities of X: when it is lower than displayStyle, the compact style is used. When it is greater or egal, the expanded style is used.

If X is a data.frame, displayStyle can have the same length as X, or can be of length 1 (and be recycled).

limDiscreteY

[numeric] : r2lb distinguishes two kinds of numeric variables: discrete designates numeric with only a few modalities, continuous designates numeric with many modalities. For the variable Y, the limit between 'few' and 'many' can be fixed by the user through the limDiscreteY argument. By setting limDiscreteY to 5, the user will ask r2lb to consider all the numeric variables with more than 5 modalities as continuous and all the variables with 5 modalities or less as discrete.

The default value for limDiscreteY is 10.

limDiscreteX

[numeric] or [vector(numeric)]: same as limDiscreteY. If X is a data.frame, limDiscreteX can have the same length as X or can be of length 1 (and is recycled).

Details

r2lb performs some basic analyses, then generates code to be included in a LaTeX document in order to print out the analyses in a (so nice!) LaTeX way.

r2lb performs the analyses automatically according to the data class. It considers 5 classes: nominal with 2 modalities, nominal with 3 modalities or more, ordered, discrete and continuous (see the description of limDiscreteY for details on discrete and continuous).

The analysis of the variable depends on the class of Y and X wich gives 25 possible combinations. We will not give a description here, all of them are presented in the pdf file /library/r2lh/doc/r2lhOutput.pdf.

They can be divided in two categories. First (on the top of the tabular) are descriptive analyses:

  1. table: absolute and relative frequency.

  2. summary: mainly whenY is continuous and X has few modalities.

  3. graphical representation: barplot or boxplot for each modalities of X, mosaic plot, scatter plot, density lines according to the type of the variable.

On the second part of the tabular are all the informations related to a potential link between Y and X.

  1. test: khi2, Fisher exact test, Student's T, ANOVA, Wilcoxon, Kruskal & Wallis, Spearman correlation, Pearson correlation, Odds Ratio and Relative Risk, depending on the classes of Y and X. Note that as many tests as possible are run. For example, if Y is nominal and Xis ordered, X can be considered as a factor (khi2 and Fisher exact test) but also as a discrete variable (Wilcoxon).

  2. graphical diagnostic: the test presented might not be all valid. Some graphical diagnostic (check for normality) are presented to let the user decide which test is more relevant.

The wide display gives :

1
2
3
4
5
6
+---+---+---+
| 1 | 2 | 3 |
+---+-+-+---+
|  4  |  5  |
+-----+-----+
  

The long display :

1
2
3
4
5
6
7
8
+-------+
|   1   |
+---+---+
| 2 | 3 |
+---+---+
| 4 | 5 |
+---+---+
  

If X is a data.frame, r2lb runs the analyses on every column.

See /library/r2lh/doc/r2lhOutput.pdf for display details.

Value

r2lb generates LaTeX code and either prints it on the screen, or saves it in a file. It also generates several graphs, optionally in a different directory.

Classical usage

The use of r2lb goes through the following steps:

Step 1. Load the data (usually, a data.frame).
Step 2. Optionally, set some variables as ordered.
Step 3. Run r2lb(Y~dataFrame,"fileOut.tex").

See examples of application.

Author

Christophe Genolini
christophe.genolini@free.fr
PSIGIAM: Paris Sud Innovation Group in Adolescent Mental Health
INSERM U669 / Maison de Solenn / Paris

Bernard Desgraupes
bernard.desgraupes@u-paris10.fr
University of Paris Ouest - Nanterre

References

LaTeX web site http://www.latex-project.org/
Data are available on line: http://christophe.genolini.free.fr/EPO/EPO2007-Fraude.php

See Also

r2lMainFile, r2lu, r2latexUniv-package, examCheating, Sweave, latex

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
 # # # # # # # # # # # # # # # # # # #
#    R to LaTeX, Bivariate Analyses   #
 #        Artificial examples        #
  #         Single variable         #
   # # # # # # # # # # # # # # # # #

### Create some data
V1 <- factor(LETTERS[floor(runif(50,1,4))])
V2 <- rnorm(50,1,1)<0
V3 <- ordered(LETTERS[floor(runif(50,1,4))])

### Create a directory for the output
if(!file.exists("tmp/r2lbExample",recursive=TRUE)){dir.create("tmp/r2lbExample",recursive=TRUE)}else{}
setwd("tmp/r2lbExample")

### Execute r2lb
r2lb(V1~V2,fileOut="first.tex",textBefore="\\section{Variables V1, V2, V3}",graphName="Gr1",type="postscript")
r2lb(V2~V1,fileOut="second.tex",graphName="Gr2",type="postscript")
r2lb(V3~V1,fileOut="third.tex",textBefore="This is V3 vs. V1",graphDir="P",graphName="Gr3",type="postscript",displayStyle=2)
r2lMainFile(text="\\input{first.tex}\n\\input{second.tex}\n\\input{third.tex}")
setwd("../..")

r2lh documentation built on May 29, 2017, 12:11 p.m.