1 / 33

An introduction to R: get familiar with R

An introduction to R: get familiar with R. Guangxu Liu Bio7932. Outline. 1. Download and installation of R 2. Get familiar with R 3. Input data and read data from file 4. Commonly used R code 5. Something need to be aware 6. Reference for R Step by step proc.

aricin
Download Presentation

An introduction to R: get familiar with R

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An introduction to R: get familiar with R Guangxu Liu Bio7932

  2. Outline 1. Download and installation of R 2. Get familiar with R 3. Input data and read data from file 4. Commonly used R code 5. Something need to be aware 6. Reference for R Step by step proc.

  3. 1.Downloading R official website: www.R-project.org Where to download R.

  4. After we choose the correct server and computer system, we will get something like below. What we want is here!

  5. Choose again?!! Here it is!

  6. Installation: Proc: Simply use the download installation file. Available options: Choose install direction language (English, simple Chinese only) ? Set up the methods for viewing help information(html, txt, chm) Select components, customize ….

  7. 2. Get familiar with R (Sorry about using chinese version) File; Edit; Others; Package; Help function Basic introduction of R, such as Version… Working place, where we write code, see the verbal or numerial results

  8. 3. Input data and read data from file Basic proc: x<-function() x=data name; <- assignment; function()=the methods for reading data Function(): c() for example, x<-c(1,2,3,4,5) read.table() scan() Read data using Rcmdr package

  9. Examples: Read data with Rcmdr package Load package from package option

  10. Rcmdr

  11. Rcmdr windows (right windows below)

  12. Rcmdr-Data-Inport data (Thanks god, Rcmdr is in English!) File can be read by Rcmdr includes txt,spss,mintab,stata,excel….

  13. For example: open the excel file contains the data, select the data you want to input and copy it by right click and copy or ctl+c. Then switch back to Rcmdr windows and choose data input from txt & clipboard

  14. Data name 1.Variable name in first line or not 2. NA How the data are separated (Tabs here for excel)

  15. All setting looks fine now Read the data

  16. The R code for what we did Output window? Do not show graphic results General information of the data

  17. An example show how t-test results displayed in output windows T test R code Results form the t-test

  18. Lot’s functions here, such as make graph, load statistics package

  19. If we make graph (box plot for example) R code for box plot

  20. Graph result shows in R graphics window (right windows)

  21. View data and edit data after data input View data and edit your data View data window shows the data

  22. Edit data in the data edit windows

  23. 4. Commonly used R code ls() show all the available data (objects) in the work space or memory rm() delete data, remove objects ? get online help about *** lm() fit a simple regression and look at it resid() residuals from one model fitted() fits from one model plot() scatter plot 5. Something needs to be kept in mind Capital letter matters: v≠V Data (Objects) are vector or matrix Some examples

  24. Use ls() show the data in workspace VCL and vcl are different data objects Commends: don’t use capital letter at all is a good idea

  25. Online help (don’t need internet connection in fact) Use “?ls” to learn more about ls() fuction

  26. Use ?lm learn more about lm() There are lot’s components in lm() Details about all those components

  27. A simple example (without data input part) Use f to view the data f in workspace Step 1: Read and built a new data with name f Data from fertilization data of Liu (2006), and we know there should have a simple linear relationship between ln and density. Density=log(sperm/egg density) ln=log(fertilized egg/unfertilized egg). So the model will be ln=a+b*density+error

  28. Use fm<-lm(ln~density,data=f) to build up the linear model fm<-lm(ln~density,data=f) Assign fm as the linear model Model is based on ln and density, use ln as dependent and density as variable There ln and density come from

  29. Use fm to view fm Shows what’s fm

  30. Use summary(fm) to see more details Details of fm, including df, SE, t value and P

  31. Use plot(fitted(fm),resid(fm),xlab="fitted",ylab="residual",main="residual vs fits") check residual vs fits. Graph shown on the right side window Here xlab(),ylab(),main() are R codes to give x,y and the whole graph labels.

  32. 6.Reference for R (http://www.r-project.org) This makes me change my presentation title to “An introduction to R:get familiar with R” 1.Free reference on R official website 2. Practical Regression and Anova using R, Julian J. Faraway, 2002

  33. Thanks Picture above from www.R-project.org

More Related