Introduction to R Sofware Advanced Herd Management Ccile Cornou 1 - - PDF document

introduction to r sofware
SMART_READER_LITE
LIVE PREVIEW

Introduction to R Sofware Advanced Herd Management Ccile Cornou 1 - - PDF document

Introduction to R Sofware Advanced Herd Management Ccile Cornou 1 What is R? Programming environment for data analysis, statistical methods and graphical display Use a programming language very similar to S Object oriented


slide-1
SLIDE 1

1

1

Introduction to R Sofware

Advanced Herd Management Cécile Cornou

2

What is R?

  • Programming environment for data

analysis, statistical methods and graphical display

  • Use a programming language very similar

to S

  • Object oriented system
  • Built-in or ”hand made” functions to apply
  • n objects
slide-2
SLIDE 2

2

3

Access and Documentation

  • Downloading (Free software)

Comprehensive R Archive Network http://cran.r-project.org

  • Documentation

”An Introduction to R” (from cran website)

W.N. Venables, D.M. Smith and the R Development Core Team

4

Getting started with R

  • The R console
  • Set a working directory
  • Edit as text file (as notepad) and

copy/paste

  • Import data from an excel spread sheet

Previously saved as ”csv” file / Located in your directory

  • First calculation and plotting
  • Export data
slide-3
SLIDE 3

3

5

The R console

6

Working Directory (to import and export your data)

slide-4
SLIDE 4

4

7

Read data

8

Summary of the data and Plotting (basic)

slide-5
SLIDE 5

5

9

Plotting (enhanced)

10

Moving Average – R programming

Here we use a created function ”movAve” to calculate

  • the moving average of the daily gain
  • the upper and lower control limits using the expected mean

(mean1) and standard deviation of the process in control (sd1) movAve <- function(vector,span,nosigma,mean1,sd1) { n <- length(vector); ma <- rep(NA,n); for (i in (span : n)) { x <- c(vector[(i-span+1):i]); ma[i] <- mean(x); } ucl <- mean1 + nosigma*sd1; lcl <- mean1 - nosigma*sd1; return(list(ma=ma,ucl=ucl,lcl=lcl)); } Create an empty data frame to store the results res.ma <- data.frame() Calculate and store the results in the data frame res.ma <- movAve(table$Observed.gain,4,2,750,20) Add the moving average to our table table$ma <- res.ma$ma Finally we can save the new table as csv file for further calculations write.table(table,file=”adg2.csv”)

slide-6
SLIDE 6

6

11

Control Chart: Moving Average