Book contents
- Frontmatter
- Contents
- Preface
- Acknowledgements
- 1 Prologue
- 2 A beginners’ guide
- 3 Python basics
- 4 Program control and logic
- 5 Functions
- 6 Files
- 7 Object orientation
- 8 Object data modelling
- 9 Mathematics
- 10 Coding tips
- 11 Biological sequences
- 12 Pairwise sequence alignments
- 13 Multiple-sequence alignments
- 14 Sequence variation and evolution
- 15 Macromolecular structures
- 16 Array data
- 17 High-throughput sequence analyses
- 18 Images
- 19 Signal processing
- 20 Databases
- 21 Probability
- 22 Statistics
- 23 Clustering and discrimination
- 24 Machine learning
- 25 Hard problems
- 26 Graphical interfaces
- 27 Improving speed
- Appendices
- Appendix 1 Simplified language reference
- Appendix 2 Selected standard type methods and operations
- Appendix 3 Standard module highlights
- Appendix 4 String formatting
- Appendix 5 Regular expressions
- Appendix 6 Further statistics
- Glossary
- Index
- Plate section
Appendix 6 - Further statistics
Published online by Cambridge University Press: 05 February 2015
- Frontmatter
- Contents
- Preface
- Acknowledgements
- 1 Prologue
- 2 A beginners’ guide
- 3 Python basics
- 4 Program control and logic
- 5 Functions
- 6 Files
- 7 Object orientation
- 8 Object data modelling
- 9 Mathematics
- 10 Coding tips
- 11 Biological sequences
- 12 Pairwise sequence alignments
- 13 Multiple-sequence alignments
- 14 Sequence variation and evolution
- 15 Macromolecular structures
- 16 Array data
- 17 High-throughput sequence analyses
- 18 Images
- 19 Signal processing
- 20 Databases
- 21 Probability
- 22 Statistics
- 23 Clustering and discrimination
- 24 Machine learning
- 25 Hard problems
- 26 Graphical interfaces
- 27 Improving speed
- Appendices
- Appendix 1 Simplified language reference
- Appendix 2 Selected standard type methods and operations
- Appendix 3 Standard module highlights
- Appendix 4 String formatting
- Appendix 5 Regular expressions
- Appendix 6 Further statistics
- Glossary
- Index
- Plate section
Summary
RPy and the R statistical package
The R statistical package is one of the most commonly used ones for analysing statistical data. It has its own language. There is a Python wrapper around it called RPy.2 The main reason to use RPy would be if you have lots of existing R code that you wish to interface to in Python.
There are a few things to keep in mind when using RPy. Standard Python collection types or NumPy arrays have to be converted into special RPy data types, and results that are returned from R have to be suitably interpreted. Reading the R documentation is crucial to using RPy.
We will illustrate the use of R via RPy for a few standard examples.
Binomial test
First we consider the binomial test, which is concerned with the number of occurrences of an event that has a fixed probability of occurring, given a certain number of trials. R has a method, ‘binom.test’, to do the binomial test. We create a function, binomialTailTest(), which calls this method via RPy, and which has the same arguments as in our previous version of the function in Chapter 22, which used SciPy.
First we need to import the RPy module, rpy2.robjects, which we call R below. This has an object inside it, R.r, which is what we use to get hold of R methods, using dictionary syntax keyed on the name of the R method. Here we want to use the R method binom.test, and so R.r['binom.test'] is the Python version of this R method.
- Type
- Chapter
- Information
- Python Programming for BiologyBioinformatics and Beyond, pp. 668 - 670Publisher: Cambridge University PressPrint publication year: 2015