SlideShare a Scribd company logo

Mixed Effects Models - Descriptive Statistics

Lecture 2 from my mixed-effects modeling course: Descriptive statistics in R

Mixed Effects Models - Descriptive Statistics

1 of 65
Download to read offline
R Basics
R Basics
Week 2.1: Descriptive Statistics in R
! R commands & functions
! Tidyverse & the Pipe Operator
! Multiple Functions
! Reading in data
! Saving R scripts
! Descriptive statistics
! 1 variable
! 2 variable
! Grouping
! Plotting
! Scatterplot
! Bar graph
R Commands
! Simplest way to interact with R is by
typing in commands at the > prompt:
R STUDIO R
R as a Calculator
! Typing in a simple calculation shows us
the result:
! 608 + 28
! What’s 11527 minus 283?
! Some more examples:
! 400 / 65 (division)
! 2 * 4 (multiplication)
! 5 ^ 2 (exponentiation)
Functions
! More complex calculations can be done
with functions:
! sqrt(64)
! Can often read these
left to right (“square root of 64”)
! What do you think
this means?
! abs(-7)
What the function
is (square root)
In parenthesis: What
we want to perform the
function on

Recommended

Mixed Effects Models - Fixed Effect Interactions
Mixed Effects Models - Fixed Effect InteractionsMixed Effects Models - Fixed Effect Interactions
Mixed Effects Models - Fixed Effect InteractionsScott Fraundorf
 
Mixed Effects Models - Introduction
Mixed Effects Models - IntroductionMixed Effects Models - Introduction
Mixed Effects Models - IntroductionScott Fraundorf
 
Mixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical LogitMixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical LogitScott Fraundorf
 
Mixed Effects Models - Centering and Transformations
Mixed Effects Models - Centering and TransformationsMixed Effects Models - Centering and Transformations
Mixed Effects Models - Centering and TransformationsScott Fraundorf
 
Mixed Effects Models - Data Processing
Mixed Effects Models - Data ProcessingMixed Effects Models - Data Processing
Mixed Effects Models - Data ProcessingScott Fraundorf
 
Mixed Effects Models - Fixed Effects
Mixed Effects Models - Fixed EffectsMixed Effects Models - Fixed Effects
Mixed Effects Models - Fixed EffectsScott Fraundorf
 
Mixed Effects Models - Simple and Main Effects
Mixed Effects Models - Simple and Main EffectsMixed Effects Models - Simple and Main Effects
Mixed Effects Models - Simple and Main EffectsScott Fraundorf
 
Mixed Effects Models - Model Comparison
Mixed Effects Models - Model ComparisonMixed Effects Models - Model Comparison
Mixed Effects Models - Model ComparisonScott Fraundorf
 

More Related Content

What's hot

Mixed Effects Models - Random Intercepts
Mixed Effects Models - Random InterceptsMixed Effects Models - Random Intercepts
Mixed Effects Models - Random InterceptsScott Fraundorf
 
Mixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random EffectsMixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random EffectsScott Fraundorf
 
Mixed Effects Models - Orthogonal Contrasts
Mixed Effects Models - Orthogonal ContrastsMixed Effects Models - Orthogonal Contrasts
Mixed Effects Models - Orthogonal ContrastsScott Fraundorf
 
Mixed Effects Models - Random Slopes
Mixed Effects Models - Random SlopesMixed Effects Models - Random Slopes
Mixed Effects Models - Random SlopesScott Fraundorf
 
Mixed Effects Models - Post-Hoc Comparisons
Mixed Effects Models - Post-Hoc ComparisonsMixed Effects Models - Post-Hoc Comparisons
Mixed Effects Models - Post-Hoc ComparisonsScott Fraundorf
 
Mixed Effects Models - Effect Size
Mixed Effects Models - Effect SizeMixed Effects Models - Effect Size
Mixed Effects Models - Effect SizeScott Fraundorf
 
Mixed Effects Models - Growth Curve Analysis
Mixed Effects Models - Growth Curve AnalysisMixed Effects Models - Growth Curve Analysis
Mixed Effects Models - Growth Curve AnalysisScott Fraundorf
 
Mixed Effects Models - Signal Detection Theory
Mixed Effects Models - Signal Detection TheoryMixed Effects Models - Signal Detection Theory
Mixed Effects Models - Signal Detection TheoryScott Fraundorf
 
Forecasting with Vector Autoregression
Forecasting with Vector AutoregressionForecasting with Vector Autoregression
Forecasting with Vector AutoregressionBryan Butler, MBA, MS
 
Stat 1163 -correlation and regression
Stat 1163 -correlation and regressionStat 1163 -correlation and regression
Stat 1163 -correlation and regressionKhulna University
 
Why start using uplift models for more efficient marketing campaigns
Why start using uplift models for more efficient marketing campaignsWhy start using uplift models for more efficient marketing campaigns
Why start using uplift models for more efficient marketing campaignsData Con LA
 
Macroeconomic modelling using Eviews
Macroeconomic modelling using EviewsMacroeconomic modelling using Eviews
Macroeconomic modelling using EviewsMuhammad Anees
 
Rでベイズをやってみよう!(コワい本1章)@BCM勉強会
Rでベイズをやってみよう!(コワい本1章)@BCM勉強会Rでベイズをやってみよう!(コワい本1章)@BCM勉強会
Rでベイズをやってみよう!(コワい本1章)@BCM勉強会Shushi Namba
 
SEM(structural equation modeling)結構方程模型-潛在成長模型-三星統計張偉豪-20140828
SEM(structural equation modeling)結構方程模型-潛在成長模型-三星統計張偉豪-20140828SEM(structural equation modeling)結構方程模型-潛在成長模型-三星統計張偉豪-20140828
SEM(structural equation modeling)結構方程模型-潛在成長模型-三星統計張偉豪-20140828Beckett Hsieh
 
Chapter7 回帰分析の悩みどころ
Chapter7 回帰分析の悩みどころChapter7 回帰分析の悩みどころ
Chapter7 回帰分析の悩みどころitoyan110
 
2.4 Scatterplots, correlation, and regression
2.4 Scatterplots, correlation, and regression2.4 Scatterplots, correlation, and regression
2.4 Scatterplots, correlation, and regressionLong Beach City College
 
RでGARCHモデル - TokyoR #21
RでGARCHモデル - TokyoR #21RでGARCHモデル - TokyoR #21
RでGARCHモデル - TokyoR #21horihorio
 
第4回DARM勉強会 (構造方程式モデリング)
第4回DARM勉強会 (構造方程式モデリング)第4回DARM勉強会 (構造方程式モデリング)
第4回DARM勉強会 (構造方程式モデリング)Yoshitake Takebayashi
 

What's hot (20)

Mixed Effects Models - Random Intercepts
Mixed Effects Models - Random InterceptsMixed Effects Models - Random Intercepts
Mixed Effects Models - Random Intercepts
 
Mixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random EffectsMixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random Effects
 
Mixed Effects Models - Orthogonal Contrasts
Mixed Effects Models - Orthogonal ContrastsMixed Effects Models - Orthogonal Contrasts
Mixed Effects Models - Orthogonal Contrasts
 
Mixed Effects Models - Random Slopes
Mixed Effects Models - Random SlopesMixed Effects Models - Random Slopes
Mixed Effects Models - Random Slopes
 
Mixed Effects Models - Post-Hoc Comparisons
Mixed Effects Models - Post-Hoc ComparisonsMixed Effects Models - Post-Hoc Comparisons
Mixed Effects Models - Post-Hoc Comparisons
 
Mixed Effects Models - Effect Size
Mixed Effects Models - Effect SizeMixed Effects Models - Effect Size
Mixed Effects Models - Effect Size
 
Mixed Effects Models - Growth Curve Analysis
Mixed Effects Models - Growth Curve AnalysisMixed Effects Models - Growth Curve Analysis
Mixed Effects Models - Growth Curve Analysis
 
Mixed Effects Models - Signal Detection Theory
Mixed Effects Models - Signal Detection TheoryMixed Effects Models - Signal Detection Theory
Mixed Effects Models - Signal Detection Theory
 
Forecasting with Vector Autoregression
Forecasting with Vector AutoregressionForecasting with Vector Autoregression
Forecasting with Vector Autoregression
 
ggplotのplotエリアで日本語ラベルを使う
ggplotのplotエリアで日本語ラベルを使うggplotのplotエリアで日本語ラベルを使う
ggplotのplotエリアで日本語ラベルを使う
 
Stat 1163 -correlation and regression
Stat 1163 -correlation and regressionStat 1163 -correlation and regression
Stat 1163 -correlation and regression
 
Why start using uplift models for more efficient marketing campaigns
Why start using uplift models for more efficient marketing campaignsWhy start using uplift models for more efficient marketing campaigns
Why start using uplift models for more efficient marketing campaigns
 
Macroeconomic modelling using Eviews
Macroeconomic modelling using EviewsMacroeconomic modelling using Eviews
Macroeconomic modelling using Eviews
 
Rでベイズをやってみよう!(コワい本1章)@BCM勉強会
Rでベイズをやってみよう!(コワい本1章)@BCM勉強会Rでベイズをやってみよう!(コワい本1章)@BCM勉強会
Rでベイズをやってみよう!(コワい本1章)@BCM勉強会
 
SEM(structural equation modeling)結構方程模型-潛在成長模型-三星統計張偉豪-20140828
SEM(structural equation modeling)結構方程模型-潛在成長模型-三星統計張偉豪-20140828SEM(structural equation modeling)結構方程模型-潛在成長模型-三星統計張偉豪-20140828
SEM(structural equation modeling)結構方程模型-潛在成長模型-三星統計張偉豪-20140828
 
Chapter7 回帰分析の悩みどころ
Chapter7 回帰分析の悩みどころChapter7 回帰分析の悩みどころ
Chapter7 回帰分析の悩みどころ
 
2.4 Scatterplots, correlation, and regression
2.4 Scatterplots, correlation, and regression2.4 Scatterplots, correlation, and regression
2.4 Scatterplots, correlation, and regression
 
RでGARCHモデル - TokyoR #21
RでGARCHモデル - TokyoR #21RでGARCHモデル - TokyoR #21
RでGARCHモデル - TokyoR #21
 
第4回DARM勉強会 (構造方程式モデリング)
第4回DARM勉強会 (構造方程式モデリング)第4回DARM勉強会 (構造方程式モデリング)
第4回DARM勉強会 (構造方程式モデリング)
 
Linear regression theory
Linear regression theoryLinear regression theory
Linear regression theory
 

Similar to Mixed Effects Models - Descriptive Statistics

R programming slides
R  programming slidesR  programming slides
R programming slidesPankaj Saini
 
Language-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchLanguage-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchAndrew Lowe
 
Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016Spencer Fox
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packagesAjay Ohri
 
An Introduction To Statistical Computing in R.pdf
An Introduction To Statistical Computing in R.pdfAn Introduction To Statistical Computing in R.pdf
An Introduction To Statistical Computing in R.pdfMonique Carr
 

Similar to Mixed Effects Models - Descriptive Statistics (20)

محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
 
R programming slides
R  programming slidesR  programming slides
R programming slides
 
Language-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchLanguage-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible research
 
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
 
Unit 3
Unit 3Unit 3
Unit 3
 
e_lumley.pdf
e_lumley.pdfe_lumley.pdf
e_lumley.pdf
 
Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
 
Hadoop map reduce concepts
Hadoop map reduce conceptsHadoop map reduce concepts
Hadoop map reduce concepts
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
 
Lecture1 r
Lecture1 rLecture1 r
Lecture1 r
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
An Introduction To Statistical Computing in R.pdf
An Introduction To Statistical Computing in R.pdfAn Introduction To Statistical Computing in R.pdf
An Introduction To Statistical Computing in R.pdf
 

More from Scott Fraundorf

Mixed Effects Models - Power
Mixed Effects Models - PowerMixed Effects Models - Power
Mixed Effects Models - PowerScott Fraundorf
 
Mixed Effects Models - Autocorrelation
Mixed Effects Models - AutocorrelationMixed Effects Models - Autocorrelation
Mixed Effects Models - AutocorrelationScott Fraundorf
 
Mixed Effects Models - Missing Data
Mixed Effects Models - Missing DataMixed Effects Models - Missing Data
Mixed Effects Models - Missing DataScott Fraundorf
 
Mixed Effects Models - Logit Models
Mixed Effects Models - Logit ModelsMixed Effects Models - Logit Models
Mixed Effects Models - Logit ModelsScott Fraundorf
 
Mixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 VariablesMixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 VariablesScott Fraundorf
 

More from Scott Fraundorf (6)

Mixed Effects Models - Power
Mixed Effects Models - PowerMixed Effects Models - Power
Mixed Effects Models - Power
 
Mixed Effects Models - Autocorrelation
Mixed Effects Models - AutocorrelationMixed Effects Models - Autocorrelation
Mixed Effects Models - Autocorrelation
 
Mixed Effects Models - Missing Data
Mixed Effects Models - Missing DataMixed Effects Models - Missing Data
Mixed Effects Models - Missing Data
 
Mixed Effects Models - Logit Models
Mixed Effects Models - Logit ModelsMixed Effects Models - Logit Models
Mixed Effects Models - Logit Models
 
Mixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 VariablesMixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 Variables
 
Scott_Fraundorf_Resume
Scott_Fraundorf_ResumeScott_Fraundorf_Resume
Scott_Fraundorf_Resume
 

Recently uploaded

The Institutional Origins of Canada’s Telecommunications Mosaic
The Institutional Origins of Canada’s Telecommunications MosaicThe Institutional Origins of Canada’s Telecommunications Mosaic
The Institutional Origins of Canada’s Telecommunications MosaicUniversity of Canberra
 
SOCIAL JUSTICE LESSON ON CATCH UP FRIDAY
SOCIAL JUSTICE LESSON ON CATCH UP FRIDAYSOCIAL JUSTICE LESSON ON CATCH UP FRIDAY
SOCIAL JUSTICE LESSON ON CATCH UP FRIDAYGloriaRamos83
 
Introduction of General Pharmacology PPT.pptx
Introduction of General Pharmacology PPT.pptxIntroduction of General Pharmacology PPT.pptx
Introduction of General Pharmacology PPT.pptxRenuka N Sunagad
 
EDL 290F Week 1 - Meet Me at the Start Line.pdf
EDL 290F Week 1 - Meet Me at the Start Line.pdfEDL 290F Week 1 - Meet Me at the Start Line.pdf
EDL 290F Week 1 - Meet Me at the Start Line.pdfElizabeth Walsh
 
2.15.24 Making Whiteness -- Baldwin.pptx
2.15.24 Making Whiteness -- Baldwin.pptx2.15.24 Making Whiteness -- Baldwin.pptx
2.15.24 Making Whiteness -- Baldwin.pptxMaryPotorti1
 
DISCOURSE: TEXT AS CONNECTED DISCOURSE
DISCOURSE:   TEXT AS CONNECTED DISCOURSEDISCOURSE:   TEXT AS CONNECTED DISCOURSE
DISCOURSE: TEXT AS CONNECTED DISCOURSEMYDA ANGELICA SUAN
 
Bayesian Analysis Fundamentals with Examples
Bayesian Analysis Fundamentals with ExamplesBayesian Analysis Fundamentals with Examples
Bayesian Analysis Fundamentals with ExamplesTushar Tank
 
FILIPINO 7 IKATLO AT IKAAPAT NA LINGGO 3RD QUARTER.pptx
FILIPINO 7 IKATLO AT IKAAPAT NA LINGGO 3RD QUARTER.pptxFILIPINO 7 IKATLO AT IKAAPAT NA LINGGO 3RD QUARTER.pptx
FILIPINO 7 IKATLO AT IKAAPAT NA LINGGO 3RD QUARTER.pptxmarielouisemiranda1
 
History in your Hands slides - Class 4 (online version).pptx
History in your Hands slides - Class 4 (online version).pptxHistory in your Hands slides - Class 4 (online version).pptx
History in your Hands slides - Class 4 (online version).pptxEilsONeill
 
CONCEPTS OF ENVIRONMENT & ECOSYSTEM.pptx
CONCEPTS OF ENVIRONMENT & ECOSYSTEM.pptxCONCEPTS OF ENVIRONMENT & ECOSYSTEM.pptx
CONCEPTS OF ENVIRONMENT & ECOSYSTEM.pptxAnupkumar Sharma
 
Shapley Tech Talk - SHAP and Shapley Discussion
Shapley Tech Talk - SHAP and Shapley DiscussionShapley Tech Talk - SHAP and Shapley Discussion
Shapley Tech Talk - SHAP and Shapley DiscussionTushar Tank
 
Unleashing the Power of AI Tools for Enhancing Research, International FDP on...
Unleashing the Power of AI Tools for Enhancing Research, International FDP on...Unleashing the Power of AI Tools for Enhancing Research, International FDP on...
Unleashing the Power of AI Tools for Enhancing Research, International FDP on...Dr. Vinod Kumar Kanvaria
 
Media Relations for Public Relations Class
Media Relations for Public Relations ClassMedia Relations for Public Relations Class
Media Relations for Public Relations ClassCorinne Weisgerber
 
Practical Research 1: Nature of Inquiry and Research.pptx
Practical Research 1: Nature of Inquiry and Research.pptxPractical Research 1: Nature of Inquiry and Research.pptx
Practical Research 1: Nature of Inquiry and Research.pptxKatherine Villaluna
 
BTKi in Treatment Of Chronic Lymphocytic Leukemia
BTKi in Treatment Of Chronic Lymphocytic LeukemiaBTKi in Treatment Of Chronic Lymphocytic Leukemia
BTKi in Treatment Of Chronic Lymphocytic LeukemiaFaheema Hasan
 
John See - Narrative Story
John See - Narrative StoryJohn See - Narrative Story
John See - Narrative StoryAlan See
 

Recently uploaded (20)

Caldecott Medal Book Winners and Media Used
Caldecott Medal Book Winners and Media UsedCaldecott Medal Book Winners and Media Used
Caldecott Medal Book Winners and Media Used
 
The Institutional Origins of Canada’s Telecommunications Mosaic
The Institutional Origins of Canada’s Telecommunications MosaicThe Institutional Origins of Canada’s Telecommunications Mosaic
The Institutional Origins of Canada’s Telecommunications Mosaic
 
SOCIAL JUSTICE LESSON ON CATCH UP FRIDAY
SOCIAL JUSTICE LESSON ON CATCH UP FRIDAYSOCIAL JUSTICE LESSON ON CATCH UP FRIDAY
SOCIAL JUSTICE LESSON ON CATCH UP FRIDAY
 
Introduction of General Pharmacology PPT.pptx
Introduction of General Pharmacology PPT.pptxIntroduction of General Pharmacology PPT.pptx
Introduction of General Pharmacology PPT.pptx
 
EDL 290F Week 1 - Meet Me at the Start Line.pdf
EDL 290F Week 1 - Meet Me at the Start Line.pdfEDL 290F Week 1 - Meet Me at the Start Line.pdf
EDL 290F Week 1 - Meet Me at the Start Line.pdf
 
2.15.24 Making Whiteness -- Baldwin.pptx
2.15.24 Making Whiteness -- Baldwin.pptx2.15.24 Making Whiteness -- Baldwin.pptx
2.15.24 Making Whiteness -- Baldwin.pptx
 
first section physiology laboratory.pptx
first section physiology laboratory.pptxfirst section physiology laboratory.pptx
first section physiology laboratory.pptx
 
DISCOURSE: TEXT AS CONNECTED DISCOURSE
DISCOURSE:   TEXT AS CONNECTED DISCOURSEDISCOURSE:   TEXT AS CONNECTED DISCOURSE
DISCOURSE: TEXT AS CONNECTED DISCOURSE
 
Bayesian Analysis Fundamentals with Examples
Bayesian Analysis Fundamentals with ExamplesBayesian Analysis Fundamentals with Examples
Bayesian Analysis Fundamentals with Examples
 
FILIPINO 7 IKATLO AT IKAAPAT NA LINGGO 3RD QUARTER.pptx
FILIPINO 7 IKATLO AT IKAAPAT NA LINGGO 3RD QUARTER.pptxFILIPINO 7 IKATLO AT IKAAPAT NA LINGGO 3RD QUARTER.pptx
FILIPINO 7 IKATLO AT IKAAPAT NA LINGGO 3RD QUARTER.pptx
 
Time-Honored Wisdom: African Teachings for VUCA Leaders
Time-Honored Wisdom: African Teachings for VUCA LeadersTime-Honored Wisdom: African Teachings for VUCA Leaders
Time-Honored Wisdom: African Teachings for VUCA Leaders
 
History in your Hands slides - Class 4 (online version).pptx
History in your Hands slides - Class 4 (online version).pptxHistory in your Hands slides - Class 4 (online version).pptx
History in your Hands slides - Class 4 (online version).pptx
 
CONCEPTS OF ENVIRONMENT & ECOSYSTEM.pptx
CONCEPTS OF ENVIRONMENT & ECOSYSTEM.pptxCONCEPTS OF ENVIRONMENT & ECOSYSTEM.pptx
CONCEPTS OF ENVIRONMENT & ECOSYSTEM.pptx
 
Capter 5 Climate of Ethiopia and the Horn GeES 1011.pdf
Capter 5 Climate of Ethiopia and the Horn GeES 1011.pdfCapter 5 Climate of Ethiopia and the Horn GeES 1011.pdf
Capter 5 Climate of Ethiopia and the Horn GeES 1011.pdf
 
Shapley Tech Talk - SHAP and Shapley Discussion
Shapley Tech Talk - SHAP and Shapley DiscussionShapley Tech Talk - SHAP and Shapley Discussion
Shapley Tech Talk - SHAP and Shapley Discussion
 
Unleashing the Power of AI Tools for Enhancing Research, International FDP on...
Unleashing the Power of AI Tools for Enhancing Research, International FDP on...Unleashing the Power of AI Tools for Enhancing Research, International FDP on...
Unleashing the Power of AI Tools for Enhancing Research, International FDP on...
 
Media Relations for Public Relations Class
Media Relations for Public Relations ClassMedia Relations for Public Relations Class
Media Relations for Public Relations Class
 
Practical Research 1: Nature of Inquiry and Research.pptx
Practical Research 1: Nature of Inquiry and Research.pptxPractical Research 1: Nature of Inquiry and Research.pptx
Practical Research 1: Nature of Inquiry and Research.pptx
 
BTKi in Treatment Of Chronic Lymphocytic Leukemia
BTKi in Treatment Of Chronic Lymphocytic LeukemiaBTKi in Treatment Of Chronic Lymphocytic Leukemia
BTKi in Treatment Of Chronic Lymphocytic Leukemia
 
John See - Narrative Story
John See - Narrative StoryJohn See - Narrative Story
John See - Narrative Story
 

Mixed Effects Models - Descriptive Statistics

  • 3. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 4. R Commands ! Simplest way to interact with R is by typing in commands at the > prompt: R STUDIO R
  • 5. R as a Calculator ! Typing in a simple calculation shows us the result: ! 608 + 28 ! What’s 11527 minus 283? ! Some more examples: ! 400 / 65 (division) ! 2 * 4 (multiplication) ! 5 ^ 2 (exponentiation)
  • 6. Functions ! More complex calculations can be done with functions: ! sqrt(64) ! Can often read these left to right (“square root of 64”) ! What do you think this means? ! abs(-7) What the function is (square root) In parenthesis: What we want to perform the function on
  • 7. Arguments ! Some functions have settings (“arguments”) that we can adjust: ! round(3.14) - Rounds off to the nearest integer (zero decimal places) ! round(3.14, digits=1) - One decimal place
  • 8. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 9. Tidyverse & the Pipe Operator ! tidyverse is a very popular add-on package for many basic data-processing tasks in R ! 2 steps to using: ! Install Tidyverse—only needs to be done once per computer
  • 10. Installing Tidyverse: RStudio • Tools menu -> Install Packages… • Type in tidyverse • Leave Install Dependencies checked • Grabs the other packages that tidyverse uses • Only need to do this once per computer!
  • 11. Installing Tidyverse : R • Packages & Data menu -> Package Installer -> Get List • Find tidyverse • Make sure to check Install Dependencies • Grabs the other packages that tidyverse uses • Only need to do this once per computer!
  • 12. Tidyverse & the Pipe Operator ! tidyverse is a very popular add-on package for many basic data-processing tasks in R ! 2 steps to using: ! Install Tidyverse—only needs to be done once per computer ! Load Tidyverse—once per R session ! library(tidyverse)
  • 13. Tidyverse & the Pipe Operator ! tidyverse provides another interface to functions—the pipe operator ! a %>% b() ! Start with a and apply function b()to it ! 3.14 %>% round() ! Helpful when we have multiple functions (as we’ll see in a moment)
  • 14. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 16. Multiple Functions ! The pipe operator makes it easy to do multiple functions in a row ! -16 %>% sqrt() %>% abs() • Start with -16 • Then take the square root • Then take the absolute value ! Don't get scared when you see multiple pipes! - Just read left to right
  • 17. Using Multiple Numbers at Once ! When we want to use multiple numbers, we concatenate them ! c(2,6,16) - A list of the numbers 2, 6, and 16 ! Sometimes a computation requires multiple numbers - c(2,6,16) %>% mean() ! Also a quick way to do the same thing to multiple different numbers: - c(16,100,144) %>% sqrt() CONCATENATE
  • 18. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 19. Modules: Week 2.1: experiment.csv ! Reading plausible versus implausible sentences ! “Scott chopped the carrots with a knife.” “Scott chopped the carrots with a spoon.” Measure reading time on final word Note: Simulated data; not a real experiment.
  • 20. Modules: Week 2.1: experiment.csv ! Reading plausible versus implausible sentences ! Reading time on critical word ! 36 subjects ! Each subject sees 30 items (sentences): half plausible, half implausible ! Interested in changes over time, so we’ll track number of trials remaining (29 vs 28 vs 27 vs 26…)
  • 21. Reading in Data ! Make sure you have the dataset at this point if you want to follow along: Canvas " Modules " Week 2.1 " experiment.csv
  • 22. Reading in Data – RStudio ! Navigate to the folder in lower-right ! More -> Set as Working Directory ! Open a “comma-separated value” file: - experiment <-read.csv('experiment.csv') Name of the “dataframe” we’re creating (whatever we want to call this dataset) read.csv is the function name File name
  • 23. Reading in Data – RStudio ! Navigate to the folder in lower-right ! More -> Set as Working Directory ! Open a “comma-separated value” file: - experiment <-read.csv('experiment.csv’) • General form of this: dataframe.name <-read.csv('filename')
  • 24. Reading in Data – Regular R ! Read in a “comma-separated value” file: - experiment <- read.csv ('/Users/scottfraundorf/Desktop/experiment.csv') Name of the “dataframe” we’re creating (whatever we want to call this dataset) read.csv is the function name Folder & file name • Drag & drop the file into R to get the full folder & filename
  • 25. Looking at the Data: Summary ! A “big picture” of the dataset: ! experiment %>% summary() ! summary() is a very important function! ! Basic info & descriptive statistics ! Check to make sure the data are correct
  • 26. Looking at the Data: Summary ! A “big picture” of the dataset: ! experiment %>% summary() ! We can use $ to refer to a specific column/variable in our dataset: ! experiment$RT %>% summary()
  • 27. Looking at the Data: Raw Data ! Let’s look at the data! ! experiment
  • 28. Looking at the Data: Raw Data ! Ack! That’s too much! How about just a few rows? ! experiment %>% head() ! experiment %>% head(n=10)
  • 29. Reading in Data: Other Formats ! Excel: ! Install the readxl package (only needs to be done once) - install.packages('readxl') - Then, to read in Excel data: - library(readxl) - experiment <- read_excel('/Users/scottfraundorf/Des ktop/experiment.xlsx', sheet=2) Excel files can have multiple sheets/tabs. In this case, we are saying to use sheet 2.
  • 30. Reading in Data: Other Formats ! SPSS: ! Uses the haven package—already installed as part of tidyverse ! Then, to read in SPSS data: - library(haven) - experiment <- read_spss('/Users/scottfraundorf/Desk top/experiment.spss') - This package also includes read_sas and read_stata
  • 31. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 32. R Scripts ! Save & reuse commands with a script R STUDIO R File -> New Document
  • 33. R Scripts ! Run commands without typing them all again ! R Studio: ! Code -> Run Region -> Run All: Run entire script ! Code -> Run Line(s): Run just what you’ve highlighted/selected ! R: - Highlight the section of script you want to run - Edit -> Execute ! Keyboard shortcut for this: - Ctrl+Enter (PC), ⌘+Enter (Mac)
  • 34. R Scripts ! Saves times when re-running analyses ! Other advantages? ! Some: - Documentation for yourself - Documentation for others - Reuse with new analyses/experiments - Quicker to run—can automatically perform one analysis after another
  • 35. R Scripts—Comments ! Add # before a line to make it a comment - Not commands to R, just notes to self (or other readers) • Can also add a # to make the rest of a line a comment • experiment$RT %>% summary() #awesome
  • 36. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 37. Descriptive Statistics ! So far, we’ve used summary() to get a high-level overview of our data ! Now, let’s use tidyverse to start testing specific descriptive statistics
  • 38. Descriptive Statistics ! Let’s try getting the mean of the RT column ! We start with our experiment dataframe… experiment %>% Dataframe name
  • 39. Descriptive Statistics ! Let’s try getting the mean of the RT column ! We start with our experiment dataframe… ! …then, we start using summarize() to build a table of descriptive statistics… experiment %>% summarize( Dataframe name
  • 40. Descriptive Statistics ! Let’s try getting the mean of the RT column ! We start with our experiment dataframe… ! …then, we start using summarize() to build a table of descriptive statistics… ! ..and, in particular, let’s get the mean() of the RT column experiment %>% summarize(MyMean=mean(RT)) Dataframe name Name of the column in the resulting table (can be whatever you want) Descriptive function Variable of interest
  • 41. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 42. Descriptive Statistics: 2 Variables ! Wow! That was complicated! ! But, once we have learned this general format, we can easily make more complex tables… ! Adds the SD (standard deviation) as a second column ! Other relevant functions: median(), min(), max() experiment %>% summarize(MyMean=mean(RT), MySD=sd(RT))
  • 43. Descriptive Statistics: 2 Variables ! Generic form: dataframe.name %>% summarize(TableHeader1=function(VariableName), TableHeader2=function(VariableName)) experiment %>% summarize(MyMean=mean(RT), MySD=sd(RT))
  • 44. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 45. Descriptive Statistics: Grouping ! We often want to look at a dependent variable as a function of some independent variable(s) ! e.g., RTs for Plausible vs. Implausible sentences ! We add an intermediate step – the group_by() function - experiment %>% group_by(Condition) %>% summarize(M=mean(RT)) - “Group the data by Condition, then get the mean RT”
  • 46. Descriptive Statistics: Grouping ! We often want to look at a dependent variable as a function of some independent variable(s) ! We add an intermediate step – the group_by() function ! Can even group by 2 or more variables: ! experiment %>% group_by(Subject, Condition) %>% summarize(M=mean(RT)) ! Each subject’s mean RT in each condition
  • 47. Descriptive Statistics: Grouping ! We often want to look at a dependent variable as a function of some independent variable(s) ! We add an intermediate step – the group_by() function ! Can even group by 2 or more variables: ! experiment %>% group_by(Subject, Condition) %>% summarize(M=mean(RT)) ! Generic version of this: ! dataframe.name %>% group_by(IndependentVar1, IndependentVar2) %>% summarize(TableHeader= function(DependentVar))
  • 48. Descriptive Statistics: Grouping ! With group_by() and the n() function, we can create contingency tables for categorical variables: - experiment %>% group_by(Subject, Condition) %>% summarize(Observations=n()) Now, we are not getting the mean of any particular dependent variable We just want a frequency count of the number of observations for each subject in each condition
  • 49. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 50. Plotting ! Tidyverse also includes a function for creating plots: ggplot() ! Each ggplot consists of two main elements: ! Mapping the variables onto one or more aesthetic elements in your plot (e.g., X and Y axes, color, line type)
  • 51. Plotting ! Tidyverse also includes a function for creating plots: ggplot() ! Each ggplot consists of two main elements: ! Mapping the variables onto one or more aesthetic elements in your plot (e.g., X and Y axes, color, line type)
  • 52. Plotting ! Tidyverse also includes a function for creating plots: ggplot() ! Each ggplot consists of two main elements: ! Mapping the variables onto one or more aesthetic elements in your plot (e.g., X and Y axes, color, line type)
  • 53. Plotting ! Tidyverse also includes a function for creating plots: ggplot() ! Each ggplot consists of two main elements: ! Mapping the variables onto one or more aesthetic elements in your plot (e.g., X and Y axes, color, line type) Day Partner Warmth
  • 54. Plotting ! Tidyverse also includes a function for creating plots: ggplot() ! Each ggplot consists of two main elements: ! Mapping the variables onto one or more aesthetic elements in your plot (e.g., X and Y axes, color, line type) ! Adding one or more visual elements (geoms) to depict each observation (e.g., points, bars, lines)
  • 55. Plotting: Scatterplot ! Does RT change over the course of the experiment? ! Basic scatterplot: ! experiment %>% ggplot(aes(x=TrialsRemaining, y=RT)) + geom_point() Here, we are saying how we want to translate the variables into visual form: the X axis will represent TrialsRemaining, and the Y axis will represent the RT variable Then, we want to represent each observation with a point
  • 57. Plotting: Scatterplot ! Our scatterplot: ! experiment %>% ggplot(aes(x=TrialsRemaining, y=RT)) + geom_point() ! More generically: ! experiment %>% ggplot(aes(x=XAxisVariableName, y=YAxisVariableName)) + geom_point()
  • 58. Plotting: Scatterplot ! We can add additional variables into the plot by specifying what aesthetic element they should be mapped to: ! experiment %>% ggplot(aes(x=TrialsRemaining, y=RT, color=Condition)) + geom_point() ! Now, we represent the Condition variable with the color of each point
  • 60. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 61. Plotting: Bar Graph ! Now let’s make a bar graph to compare conditions ! KEY POINT: A bar graph displays means-- that is, summarized data ! Thus, we first need to compute those means
  • 62. Plotting: Bar Graph ! Now let’s make a bar graph to compare conditions ! KEY POINT: A bar graph displays means-- that is, summarized data ! Thus, we first need to compute those means
  • 63. Plotting: Bar Graph ! Now let’s make a bar graph to compare conditions ! experiment %>% group_by(Condition) %>% summarize(MeanRT=mean(RT)) %>% ggplot(aes(x=Condition, fill=Condition, y=MeanRT)) + geom_col() Here, we are grouping by Condition and getting the mean RT in each condition The x-axis and bar color will represent Condition The y-axis (bar height) will represent MeanRT geom_col() for bar graphs
  • 65. Plotting: Bar Graph ! Generic form: ! dataframe.name %>% group_by(IndependentVariable) %>% summarize(M=mean(DependentVariable)) %>% ggplot(aes(x=IndependentVariable, fill=IndependentVaraible, y=M)) + geom_col()