3 descriptive statistics with R
-
Upload
naroranisha -
Category
Data & Analytics
-
view
68 -
download
2
Transcript of 3 descriptive statistics with R
Dr Nisha Arora
Descriptive Statistics with R
Contents
2
Tabulation & Cross Tabulation
Built-in Functions for Descriptive Statistics
Built-in Functions for Probability Distribution
References
3
Frequency Tables
To create a one-dimensional frequency table
Load & understand data
data = iris; names(data); help(iris)
Create frequency table for variable ‘Species’ of ‘iris’ data set
table(iris$Species)
4
Cross Tabulation
To create a two-dimensional contingency table
Load & understand data
data = iris; names(data); help(iris)
Create frequency table of sepal length of different species of
‘iris’ data set
table(iris$Sepal.Length, iris$Species)
Example_2:
mtcars; table(mtcars$cyl, mtcars$gear)
5
Cross Tabulation
To create a two-dimensional contingency table
Load & understand data
read.csv("people2.csv"); names(people2)
Create frequency table of eye color of people categorized by
sex
table2 <- table(people2$Eye.Color, people2$Sex)
6
Cross Tabulation
Table of proportions
prop.table(table2)
# table with each cell count expressed as a proportion of the
total count
prop.table(table2, margin=1)
# table with each cell count expressed as a proportion of row
total
prop.table(table2, margin=2) # table with each cell count
expressed as a proportion of column total
Table of percentages
round(prop.table(table2)*100)
7
Cross Tabulation
Table with marginal sums
add.margins(table2)
# table with row and column totals
addmargins(table2, margin=1)
# table with row total
addmargins(table2, margin= 2)
# table with column total
To perform chi-square test of association
summary(table2)
8
Cross Tabulation
To create a three-dimensional contingency table
Load & understand data
people2 <- read.csv("people2.csv"); names(people2)
Create frequency table of eye color of people categorized by
their sex & height
table(people2$Eye.Color, people2$Sex, people2$Height.Cat)
Built-in functions for Descriptive Statistics
9
Statistics Function name/command
Mean mean
Median median
Standard Deviation sd
Median Absolute Deviation mad
Variance var
Maximum Value max
Minimum Value min
Range range
Interquartile range IQR
Built-in functions for Descriptive Statistics
10
Statistics Function name/command
Quantiles quantile
Tukey’s five-number
summary
[min, I, II, III quartile, max
value]
fivenum
Sum sum
Product prod
Number of observations length
Standardize/ Computing
z-score
scale(x, center=TRUE, scale=TRUE)
Mean Centering scale(x, scale=FALSE)
Built-in functions for Probability Distribution
11
Statistics Function name/command
Normal PDF dnorm
Cumulative Normal
Probability pnorm
Normal Quantile qnorm
Random Normal Variable rnorm
Similarly, there are functions for other distributions like rbinom,
rpois, rt, runif, rf etc.
12 Source: Google Images
References
13
• Crowley, M. J. (2007). The R Book. Chichester, New
England: John Wiley & Sons, Ltd.
• An Introduction to R by W. N. Venables, D. M. Smith
and the R Core Team
• R in a Nutshell by Joseph Adler: O’Reilly
• Teetor, P. (2011). R cookbook. Sebastopol, CA:
O’Reilly Media Inc.
References
14
http://www.r-bloggers.com/
http://www.inside-r.org/blogs
https://blog.rstudio.org/
http://www.statmethods.net/
http://stats.stackexchange.com
https://www.researchgate.net
https://www.quora.com
https://github.com
References
15
https://rpubs.com/
https://www.datacamp.com/
https://www.dataquest.io/
https://www.codeschool.com/
16
Reach Out to Me
http://stats.stackexchange.com/users/79100/learner
https://www.researchgate.net/profile/Nisha_Arora2/contributions
https://www.quora.com/profile/Nisha-Arora-9
Thank You