18
R Example •Descriptive Statistics •Frequency and Histogram Diagrams •Standard Deviation

R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Embed Size (px)

Citation preview

Page 1: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

R Example

•Descriptive Statistics• Frequency and Histogram Diagrams• Standard Deviation

Page 2: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Excel

• Bar• Histogram• Box / CI’s• Line• Scatter• Pie

Page 3: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Correlation Matrix

BoxplotHistogram

Scatterplot

Page 4: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

> getwd()[1] "C:/Users/johnp_000/Documents"

> setwd()

Page 5: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Revisiting the Height Dataset

Page 6: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Dataset Input

Function FilenameObject

Page 7: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

str()

Data Types: Numbers and Factors/Categorical

Page 8: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

summary()

ece

Page 9: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Frequency Distribution, Histogram

hist(h$childHeight)

Page 10: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Area = 1

Density Plot

plot(density(h$childHeight))

Page 11: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

hist(h$childHeight,freq=F, breaks =25, ylim = c(0,0.14))curve(dnorm(x, mean=mean(h$childHeight), sd=sd(h$childHeight)), col="red", add=T)

Bimodal: two modes

Mode, Bimodal

Page 12: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Composite Charts

Page 13: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Boxplot (Box and Whiskers)

50th

75th

25th

Page 14: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Boxplot Options

Basic With Mean Split Data Among Predictors

Page 15: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Correlation

Covariance is High: r ~1

Covariance is Low: r ~0

Page 16: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Galton: Height Dataset

cor(h)Error in cor(h) : 'x' must be numeric

Initial workaround: Create data.frame without the Factors

cor() function does not handle Factors

Later we will RECODE the variable into a 0, 1

Excel correl() does not either

Data Types: Numbers and Factors/Categorical

Page 17: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Correlation Matrix for Continuous Variables

chart.Correlation(num2)PerformanceAnalytics package

Page 18: R Example Descriptive Statistics Frequency and Histogram Diagrams Standard Deviation

Correlations Matrix: Both Types

library(car)scatterplotMatrix(heights)