R EXAMPLES OF INDIVIDUAL TECHNIQUES (2019)
Reference Document by Anda Vitols
- Packages Used in These Exercises
- These exercises primarily focus on R core packages (automatically initialized)
- base = R Base package
- datasets = R Datasets package
- graphics = R Graphics package
- grDevices = R Graphics Devices and Support for Colours and Fonts
- methods = Formal Methods and Classes
- stats = R Stats package
- utils = R Utils package
- Other packages used in these exercises
- package::car - Companion to Applied Regression
- package::MASS - Support Functions and Datasets for Venables and Ripley's MASS
- package::psych - Statistics for Psychology
- 3D plotting packages: scatterplot3D / rgl / RColorBrewer
Datasets Used in These Exercises
datasets::cars
datasets::chickwts
datasets::HairEyeColor
datasets::InsectSprays
datasets::iris
datasets::lynx
datasets::mtcars
datasets::quakes
datasets::sleep
datasets::state.area
datasets::swiss
datasets::Titanic
datasets::trees
datasets::USJudgeRatings
datasets::warpbreaks
MASS::Painters
quantreg::engel
|
datasets from packages
imported datasets
manual data collection: Google Correlate, Google Search
manual data creation: using random number generators
|
- DATA VISUALIZATION
- Describing 1 Outcome Variable
- BAR CHART
- Use IF categorical measures (DO use - easy to read)
- database: datasets::chickwts - 71 observations of 2 variables-predictors
- functions: plot | barplot
- PIE CHART
- Use IF categorical measures (DON'T use - hard to read)
- database: datasets::chickwts - 71 observations of 2 variables-predictors
- functions: pie | par
- HISTOGRAM
- Use IF quantitative variable - for seeing distribution
- timeseries: datasets::lynx - values 144 of observations
- functions: hist | curve
- HISTOGRAM OVERLAY PLOTS
- Use IF quantitative - to see distribution & regression line describing distribution curve
- database: datasets::swiss - 47 observations of 7 variables-predictors
- database: datasets::iris - 150 observations of 5 variables
- functions: hist | curve | line
- BOXPLOT
- Use IF quantitative variable - to see distributions, centrality & outliers
- database: datasets::USJudgeRatings - 43 observations of 12 variables-predictors
- functions: boxplot
- Describing & Comparing 2 Outcome Variables
- MEANS BAR CHART
- Use IF bivariate association between predictor (6 categories-factors) and outcome (count-frequencies) THEN using barchart to compare group means
- database (like frequency table): datasets::InsectSprays - 72 observations of 2 variables
- GROUP BOX PLOTS
- Use IF several predictors on same quantitative outcome
- database MASS::painters - 54 observations of 5 variables
- database: import SearchData.csv (Polson) - 51 observations of 1 variables (data from "Google Correlate" for search terms across states)
- SCATTER PLOTS
- Use IF relationship between 2 quantitative variables
- package: car (Companion to Applied Regression) for plotting tools
- database: datasets::cars - 50 observations of 2 variables
- Discovering, Describing & Comparing Multiple (3+) Outcome Variables
- CLUSTERED BAR CHART
- Use IF 3 variables (1 outcome frequency - 2 predictor variables)
- table: datasets::warpbreaks - 54 observations of 3 variables
- SCATTER PLOTS FOR GROUPS
- Use IF 1 categorical, 2 quantitative variables THEN scatterplot for grouped data
- database: datasets::iris - 150 observtions of 5 variables
- SCATTERPLOT MATRICES
- Use IF look at association of several quantitative variables
- package: car
- database: datasets::iris - 150 observations of 5 varaibles
- database: import Search.Data.csv (polson) - 51 observations of 10 variables
- 3D SCATTERPLOTS
- Use IF want to view 3 variables in 3D
- packages: scatterplot3D / rgl / RColorBrewer
- database: datasets::iris - 150 observations of 5 variables
- DATA STATISTICS
- Describing 1 Outcome Variable
- FREQUENCIES (1 categorical variable)
- Use IF categorical - look at frequencies in a table
- table: google search frequencies-outcome by category-predictor
- functions: table | prop.table
- DESCRITPIVE SUMMARIES (1 quantitative variable)
- Use IF quatitative - describes distribution of variable
- packages: psych
- database: datasets::cars - 50 observations of 2 variables
- database: datasets::mtcars - 32 observations of 11 variables
- functions: summary | fivenum | boxplot.stats | psych::describe
- INFERENTIAL PROPORTION TESTS (1 proportion test)
- Use IF quantitative - single proportion hypothesis test and confidence interval
- dataset: manual - baseball team wins
- functions: prop.test Infer by compare a teams winning average to a result by chance (50%)
- INFERENTIAL MEANS T-TESTS (1-sample t-test)
- Use IF quantitative - single mean hypothesis test & confidence interval - done on 1 variable-predictor
- database: datasets::quakes - 1000 observations of 5 variables-predictors
- functions: t.test
- INFERENTIAL CHI SQUARE TESTS (1-sample goodness-of-fit test)
- Use IF categorical - 1-sample, goodness-of-fit test (one outcome - from 3 predictors)
- table: datasets::HairEyeColor - 3 dimensions x factors for each
- functions: chisq.test | margin.table
- Describing & Comparing 2 Outcome Variables
- CORRELATIONS (correlation coefficient)
- Use IF relationship between 2 quantitative variables
- database: datasets::swiss - 47 observationas of 6 variables
- BIVARIATE REGRESSION (linear regression)
- Use IF one variable predicts outocme of second varaible THEN association statistic (linear regression)
- database: datasets::trees - 31 observations of 3 variables
- MEANS T-TEST (independent 2-group t-test)
- Use IF compare means of 2 groups (quantitative variables)
- database: datasets::sleep - 20 observations of 3 variables
- PAIRED MEANS TEST (paired t-test)
- Use IF comapre means of one group, before and after intervention THEN paired t-tests
- datasets: create random number datasets -> do intervention on that dataset to create the other dataset
- MEANS ANOVA (one-factor ANOVA, one-way analysis of variance)
- Use IF compare mewns o one dimension on many groups
- datasets: create random data for 4 groups (same N and std dev, different means)
- PROPORTIONS (proportions test)
- Use IF compare proportions of 2 groups
- datasets: manual
- database: import mlb2011.csv (Poulson)
- CATEGORICAL CROSS TABS (chi-square test for independence)
- Use IF tabulate across many dimensions
- dataset: table datasets::Titanic (4 dimensions > narrow down to 2 dimenssions)
- Discovering, Describing & Comparing Multiple (3+) Outcome Variables
- REGRESSION (multiple regression)
- Use IF several varaibles to predict scores on single outcome
- database: datasets::USJudgeRatings - 34 observations of 12 variables
- 2 FACTOR ANOVA (2-factor analysis of varaiance)
- Use IF 2 categorical predictor variables, 1 quantitative outcome
- database: datasets::warpbreaks - 54 observations of 3 variables
- CLUSTERING (clustering observations/cases)
- Use IF grouping observations, based on similarities of variables
- 3 major types of clustering
- split: into number of clusters (k-means)
- hierarchical: start seperate > combine
- divide: start single > split
- database: datasets::mtcars - 32 observations of 11 variables
- database: import StateClusterData.csv (polson) - google search data
- PRINCIPLE COMPONENT FACTORS (grouping varaibles/predictors)
- If looking for most significant predictors THEN
- principle components = components as result of varaibles
- factor analysis = variables as result of factor
- database: datasets::mtcars - 32 observations of 11 variables
- STATISTICS FOR ROBUST DATA
- Procedures resistant to outliers and non-normal distributions
- ROBUST UNIVARIATE TESTS
- Use IF data that does not fit into assumptions of test
- database: datasets::state.area "US States Facts and Figures" - highly skewed with outliers
- functions: median | mean - trim | sd | mad | IQR | fivenum
- ROBUST BIVARIATE TESTS
- Use IF data that does not fit into assumptions of test
- packages: robust / robustbase / MASS / quantreg
- database: quantreg::engel - 235 observations of 2 variables
|