exploratory statistical data analysis with r software (esdar)

21
Exploratory Statistical Data Analysis With R Software (ESDAR) Swayam Prabha Lecture 3 Working with R Software Shalabh Department of Mathematics and Statistics Indian Institute of Technology Kanpur 1 Slides can be downloaded from http://home.iitk.ac.in/~shalab/sp

Upload: others

Post on 02-May-2022

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Exploratory Statistical Data Analysis With R Software (ESDAR)

Exploratory Statistical Data Analysis With R Software(ESDAR)

Swayam Prabha

Lecture 3

Working with R SoftwareShalabh

Department of Mathematics and  StatisticsIndian Institute of Technology Kanpur

1

Slides can be downloaded from http://home.iitk.ac.in/~shalab/sp

Page 2: Exploratory Statistical Data Analysis With R Software (ESDAR)

Getting Help in RSometimes, you want to search by the subject on which wewant help (e.g. data input). In such a case, typehelp.search("data input")

Then we get….2

Page 3: Exploratory Statistical Data Analysis With R Software (ESDAR)

Then we get….

Clicking over the link give required information

3

Page 4: Exploratory Statistical Data Analysis With R Software (ESDAR)

Getting Help in R'help()' for on‐line help,

or 'help.start()' for an HTML browser interface to help.

Then we get….4

Page 5: Exploratory Statistical Data Analysis With R Software (ESDAR)

5

Getting Help in R

Page 6: Exploratory Statistical Data Analysis With R Software (ESDAR)

Getting Help in ROther useful functions are find and apropos.

The find function tells us what package something is in.

For example> find("lowess") returns

[1] "package:stats"

6

Page 7: Exploratory Statistical Data Analysis With R Software (ESDAR)

Getting Help in RThe apropos returns a character vector giving the names of allobjects in the search list that match your enquiry.apropos("lm") returns

7

Page 8: Exploratory Statistical Data Analysis With R Software (ESDAR)

Worked Examples of Functions

To see a worked example just type the function name, e.g., lmfor linear models:

example(lm)

and we see the printed and graphical output produced by the lmfunction.

8

Page 9: Exploratory Statistical Data Analysis With R Software (ESDAR)

…and other details follow further 9

Page 10: Exploratory Statistical Data Analysis With R Software (ESDAR)

Demonstration of R FunctionsThis can be useful for seeing the type of things that R can do.demo(persp) [persp is a command for 3d surface plots]

…and it continues10

Page 11: Exploratory Statistical Data Analysis With R Software (ESDAR)

Demonstration of R FunctionsThis can be useful for seeing the type of things that R can do.demo(graphics)

11

Page 12: Exploratory Statistical Data Analysis With R Software (ESDAR)

Libraries in RR provides many functions and one can also write own.Functions and datasets are organised into libraries

To use a library, simply type the library function with thename of the library in brackets.

library(.)

For example, to load the spatial library type:

library(spatial)

12

Page 13: Exploratory Statistical Data Analysis With R Software (ESDAR)

Libraries in RExamples of libraries that come as a part of base package in R.

MASS : package associated with Venables and Ripley’s bookentitledModern Applied Statistics using S‐Plus.

mgcv : generalized additive models.

13

Page 14: Exploratory Statistical Data Analysis With R Software (ESDAR)

Contents of LibrariesIt is easy to use the help function to discover the contents oflibrary packages.

Here is how we find out about the contents of the spatiallibrary:library(help=spatial) returns

Information on package ‘spatial’Description:Package: spatialPriority: recommendedVersion: 7.3-8followed by a list of all the functions and data sets.

Then we get….14

Page 15: Exploratory Statistical Data Analysis With R Software (ESDAR)

15

Contents of Libraries

Page 16: Exploratory Statistical Data Analysis With R Software (ESDAR)

Installing Packages and LibrariesThe base R package contains programs for basic operations.

It does not contain some of the libraries necessary for advancedstatistical work.

Specific requirements are met by special packages.

They are downloaded and their downloading is very simple.

16

Page 17: Exploratory Statistical Data Analysis With R Software (ESDAR)

Installing Packages and LibrariesTo install any package,

• run the R program,

• then on the command line, use the install.packagesfunction to download the libraries we want.

17

Page 18: Exploratory Statistical Data Analysis With R Software (ESDAR)

Installing Packages and Libraries

The base R package contains some necessary libraries only.

Other libraries are required for advanced statistical work which are

downloaded and installed as and when required.

Run the R program, then use the install.packages command to

download the libraries.

Examples :

install.packages("ggplot2") : installs package ggplot2

install.packages("agricolae"): installs package agricolae

install.packages("DoE.base") : installs package DoE.base18

Page 19: Exploratory Statistical Data Analysis With R Software (ESDAR)

Installing Packages and Libraries

Exampleinstall.packages("ggplot2")

19

Page 20: Exploratory Statistical Data Analysis With R Software (ESDAR)

Cleaning  up the Windows

We assign names to variables when analyzing any data.

It is good practice to remove the variable names given to anydata frame at the end each session in R.

rm() command removes variable names

For example,rm(x,y,z) removes the variables x, y and z.

20

Page 21: Exploratory Statistical Data Analysis With R Software (ESDAR)

How to quit in R

Type q() to quit R.

21