Skip to main content Accessibility help
×
Hostname: page-component-848d4c4894-8kt4b Total loading time: 0 Render date: 2024-06-15T06:03:42.995Z Has data issue: false hasContentIssue false

Appendix 6 - Further statistics

Published online by Cambridge University Press:  05 February 2015

Tim J. Stevens
Affiliation:
MRC Laboratory of Molecular Biology, Cambridge
Wayne Boucher
Affiliation:
University of Cambridge
Get access

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 Biology
Bioinformatics and Beyond
, pp. 668 - 670
Publisher: Cambridge University Press
Print publication year: 2015

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Further statistics
  • Tim J. Stevens, MRC Laboratory of Molecular Biology, Cambridge, Wayne Boucher, University of Cambridge
  • Book: Python Programming for Biology
  • Online publication: 05 February 2015
  • Chapter DOI: https://doi.org/10.1017/CBO9780511843556.037
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Further statistics
  • Tim J. Stevens, MRC Laboratory of Molecular Biology, Cambridge, Wayne Boucher, University of Cambridge
  • Book: Python Programming for Biology
  • Online publication: 05 February 2015
  • Chapter DOI: https://doi.org/10.1017/CBO9780511843556.037
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Further statistics
  • Tim J. Stevens, MRC Laboratory of Molecular Biology, Cambridge, Wayne Boucher, University of Cambridge
  • Book: Python Programming for Biology
  • Online publication: 05 February 2015
  • Chapter DOI: https://doi.org/10.1017/CBO9780511843556.037
Available formats
×