Presentation is loading. Please wait.

Presentation is loading. Please wait.

Alternative text for elementary statistics www.statsoft.com/textbook/stathome.html –Elementary Concepts –Basic Statistics.

Similar presentations


Presentation on theme: "Alternative text for elementary statistics www.statsoft.com/textbook/stathome.html –Elementary Concepts –Basic Statistics."— Presentation transcript:

1 Alternative text for elementary statistics www.statsoft.com/textbook/stathome.html –Elementary Concepts –Basic Statistics

2 Introduction to R Autumn 2007 Petter Mostad mostad@chalmers.se

3 What is R? A programming language for statistical data analysis called S developed at Bell Labs. Later extended to S+. R is a free, open source version of S/S+. Available from www.r-project.orgwww.r-project.org Under active cooperative development; versions change frequently. Very popular tool in statistics community: New methods often now implemented there.

4 Basics of R Command-driven language Data (and functions) stored as named objects Objects can be fairly simple (vectors, matrices) or more comples (assembled from other objects)

5 Vectors and matrices Calculations often done on vectors or matrices Elementwise operations Subsetting, indexing Logical indexing

6 Help and documentation Use ”An introduction to R” Some recommended sections: 1.1, 1.7-1.11, 2, 5.1-5.4, 5.8, 6, 7.1, 10.1, 12.1, 12.3 help(mean) help.search(” ”) help.start()

7 Organizing your computations R has a ”current directory” Your objects are contained in your ”current workspace”, which can be saved any time Keep separate projects in separate workspaces/directories Keep it tidy!

8 Graphical visualization A ”generic” function: plot() High level commands, like pairs, image, contour... Lower level commands, adding stuff: points(), lines(), text(), title(), legend()... plotting characters pch, colors col...

9 Functions Most of R consists of functions The arguments can either be input in the right order, or using argument names Use help(...) !

10 Functions related to basic statistics For every distribution, we may: –Compute the probability density function –Compute the cumulative density function –Simulate random values from the distribution –Compute the quantiles See for example help(rnorm) pnorm, pf, pt, pchisq, ….

11 Doing tests in R For example t.test(…) can be done in R Many other tests are readily implemented: prop.test(…), binom.test(…), chisq.test(…), cor.test(…) help(test) will not work; try help.search(”test”)

12 Doing ANOVA in R Considered in R to be a part of linear modelling Use, for example, anova(lm(Y ~ factor(X1))) anova(lm(Y ~ factor(X1) + factor(X2))) etc.

13 Writing your own functions Collecting commands into a function Arguments to function Returning result as a list Assignments within functions programming: conditional statements, loops (avoid them!) etc... fix( )

14 Import and export of data Useful functions: read.table, write.table Works with mixed-type data (numbers and text columns) Works well with tab-separated data (connection to Excel) scan()

15 R packages A package: collection of functions (and data) concerning special application Contributed from different sources/persons Can be downloaded from CRAN or BioConductor must be ”loaded” with library() search() help(package = graphics) Also: Documentation from help.start()


Download ppt "Alternative text for elementary statistics www.statsoft.com/textbook/stathome.html –Elementary Concepts –Basic Statistics."

Similar presentations


Ads by Google