1
Experimental epidemiology analyses with R
and R commander
Lars T. Fadnes Centre for International Health University of Bergen
Experimental epidemiology analyses with R and R commander Lars T. - - PowerPoint PPT Presentation
Experimental epidemiology analyses with R and R commander Lars T. Fadnes Centre for International Health University of Bergen 1 Click to add an outline 2 How to install R commander? - install.packages("Rcmdr",
1
Lars T. Fadnes Centre for International Health University of Bergen
2
3
– Fieldtrials12.RData – Exercises-for-the-exp-epi-2012-03.rtf
4
– http://www.r-project.org/
– Package Install package scroll down to Rcmdr click OK
– Package Install package scroll down to Rcmdr click OK
http://statistics.fadnes.net/epi/
– Load package Rcmdr – Tools -> load Rcmdr plug-in(s) RcmdrPlugin.Cih.Epi
5
6
7
8
9
11
12
For Windows:
– Easy
to add it for you For Linux (Ubuntu etc):
(also contains a good description for installation on Mac)
13
14
15
16
– items for loading and saving script files; – for saving output and the R workspace; – and for exiting
– items (Cut, Copy, Paste, etc.) for editing the contents of the script and output windows.
– Submenus containing menu items for reading and manipulating data.
– Submenus containing menu items for a variety of basic statistical analyses.
17
– Menu items for creating simple statistical graphs.
– Menu items and submenus for obtaining numerical summaries, confidence intervals, hypothesis tests, diagnostics, and graphs for a statistical model, and for adding diagnostic quantities, such as residuals, to the data set.
– Probabilities, quantiles, and graphs of standard statistical distributions (to be used, for example, as a substitute for statistical tables) and samples from these distributions.
– Menu items for loading R packages unrelated to the Rcmdr package (e.g., to access data saved in another package), and for setting some options.
– items to obtain information about the R Commander (including this manual). As well, each R Commander dialog box has a Help button (see below).
18
– R commands generated by the R Commander – You can also type R commands directly into the script window or the R Console – The main purpose of the R Commander, however, is to avoid having to type commands.
– Printed output
– Displays error messages, warnings, and notes
– When you create graphs, these will appear in a separate window outside of the main R Commander window.
19
20
21
22
any models you might have generated
23
– Quantitative difference (one vs. two apples) – including continuous (numerical) variables – Number variables coded as vectors as default
– Qualitative difference (apples vs. pears) – Categorical – Text variables coded as factors as default
http://www.statmethods.net/input/datatypes.html
24
id id number gender male/female - (factor) treatmentarm Treatment (1=zinc, 0=placebo) - (factor) childage Age of the child in months - vector breastfed Is the child breast fed - (factor) lentils Does the child eat lentils? (0=no, 1= yes) - (factor) meat Does the child eat meat? (0=no, 1= yes) - (factor) duration Duration of diarrhea in days - vector diarsev Severe diarrhoea ≥10 stools per day - (factor) fever Did the child have fever at enrollment? - (factor) clusterzn2/4/8/16 cluster variables identifying living areas
25
– This will save your data (in the R format)
– This will save your output – Another strategy is to cut and paste what you want to save
– essential if you want to re-run the analyses later – WordPad is a better option than Word etc (does not autocorrect - change to upper case etc)
26
27
28
29
30
31
32
33
34
zinc <- subset(fieldtrials3, subset=treatmentarm=="zinc") placebo <- subset(fieldtrials3, subset=treatmentarm=="placebo")
35
36
37
placebo$childageyear frequency 0.5 1.0 1.5 2.0 2.5 10 20 30 40
38
placebo zinc 0.5 1.0 1.5 2.0 2.5 treatmentarm childageyear
39
– non-paramethric » two-sample wilcoxon test (log rank test) » Use the ’Exact’ test
40
Diarrhoea duration can be recoded into an additional categorised variable (diarlong) – Data manage variables
– Factor can be either number or word
– Listed with comma
– From lowest to highest values
all other values
missing
41
42
– Commands that extend over more than one line should have the second and subsequent lines indented by one or more spaces or tabs; all lines of a multiline command must be submitted simultaneously for execution. – Commands that include an assignment arrow (<-) will not generate printed
entered in the R Console [the command print(x <- 10), for example]. On the other hand, assignments made with the equals sign (=) produce printed output even when they normally would not (e.g., x = 10). – Commands that produce normally invisible output will occasionally cause output to be printed in the output window. This behaviour can be modified by editing the entries of the log-exceptions.txt file in the R Commander’s etc directory. – Blocks of commands enclosed by braces, i.e., {}, are not handled properly unless each command is terminated with a semicolon (;). This is poor R style, and implies that the script window is of limited use as a programming editor. For serious R programming, it would be preferable to use the script editor provided by the Windows version of R itself, or – even better – a programming editor.
43
44
45
– http://www.jstatsoft.org/v14/i09/paper
user interface to R
– http://socserv.mcmaster.ca/jfox/Getting-Started-with-the-Rcmdr.pdf
– http://www.statmethods.net/
46
47