1/110
Looks like no tags are added yet.
Object: Objects store information in R – whether that be a single number or a full data frame. You must return the object to see its contents.
Command: a directive or order that you give to a computer program to perform a task.
Tutorial 2-
Vectors: Vector is a type of object- a one dimensional data structure that stores values of the same type. Have two classes- length and class. Vectors are very useful because they can end up serving as either a row or a column of a database. Vectors are objects which store multiple elements of data.
Vector length: Determined by how many values or elements they hold
Vector Class: Determined by the kind of values (or elements) they hold- Numeric, Character, Logical (Boolean).
Numeric class vector: Stores real numbers, including whole numbers and decimals.
Character class vector: Stores text or individual characters, data must have “” around individual information when in code.
Logical (Boolean) class vector: Values strictly boolean- TRUE or FALSE (or NA). FALSE stored as 0 and TRUE stored at 1.
C() command: It allows us to combine elements to create a vector. place in the parentheses all of the elements you wish to combine into one vector, and separate each element using a comma.
Square brackets []: Reach into an object and pull out a smaller portion/ index and/or subsets objects. Most basic way to select an element is by what we will call “indexing” a vector.
Conditional Statements: statements that evaluate if a certain condition is met, and returns data based on satisfying this condition.
Boolean Values: data type that represents TRUE or FALSE
Types of Conditions: == : is equal to,
!= : is not equal to, >and >= : greater than, greater than or equal to, < and <= : less than, less than or equal to.
Tutorial 3-
Data Frames: When we load datasets into R we store them as objects called data frames. Data frames have two dimensions- rows and columns. Each row and column is a vector
Row: stores information horizontally from left to right
Column: stores information vertically from top to bottom
head() command: Way to look at or examine a data frame that has been saved as an object. Will show the first few rows of data frame.
Data: Information collected and stored in a systematic way. In this class we primarily work with datasets- data on specific topics.
Variable: The information collected about observations is organized into variables, which captures a single characteristic. (Columns)
Unit of Observation: The entities on which we collect the data. How we distinguish between unique rows in our data sets. Ex- cities or countries
Time series data: Same group compared over time
Cross Sectional data: Different groups compared at the same time.
Time series cross-sectional data: Comparing two groups over time.
$: Runs a single variable (column) within a dataframe
Nrow() command: Asks R how many rows (or observations) the data has.
Ncol(): Asks R how many columns (or variables) the data has.
Dim(): Asks R how many rows and columns a data frame has.
Summary(): Returns information about each of the variables. In the case of the character variables, it will tell you what class they are (character vs. numeric, for example) and the length of that variable (how many rows). In the case of numeric variables, it will give you useful information such as the minimum value, the maximum, etc.
** indexing: must follow the order of rows first, columns second
[__, ]: To look at a whole row leave the columns portion blank.
[ ,__]: To look at whole column leave the row portion blank.
Working directory: the default location where R looks for files and saves outputs
Getwd(): Checks the current working directory
Matrix: Type of 2D data. Matrices can only handle data where every element is the same type (e.g., all numbers or all characters). Create a matrix with- matrix(data, nrow, ncol, byrow, dimnames)
Combining Conditions: “&” looks for observations that fufill both conditions, “|” looks for values that fufill at least one condition.
Tutorial 4-
Renaming Data: datasetcolumn[datasetcolumn == “SpecificData”] <- “SpecificDataNewName”
NA: Code for missing values, lets R know that information is missing. When first importing a dataset it may use different conventions for coding missing values, typically you have access to documentation that will inform you how they coded or labelled missing values. Never put quotes around NA.
Arguments: An input places inside ().
Na.rm = TRUE/FALSE: If TRUE, the function will remove all NA values. If FALSE the NA values will stay, the default is FALSE.
Three types of data: numeric(numbers), characters(text), Boolean (TRUE/FALSE)
Factors: Data type specifically designed for handling categorical data in R. Useful for categorical data.
Nominal Data: Variables that have categories with no inherent order. Examples- Party Affiliation (e.g, Republican, Democrat, Indepedent) & Gender (Male or Female)
Ordinal Data: Variables that have categories with a natural ranking or order. Example- Beginner, Intermediate, and Advanced. Ex- Regime type (strong, weak democracy)
Numeric Variables: Variables with labeled values that have a universally-holding ranking and the distance between these rankings is known and equal. Ex- weight
Levels: In a factor variables, the list of levels is the set of values that a variable can take.
Descriptive Statistics: summaries of data
Central tendency: The typical or most likely value
Mean: The average
Median: The middle value (when all values are placed in order)
Mode:The most frequently occurring value
Dispersion: how spread out a set of numbers are.
Observable: Can directly perceive it
Objective: The definition doesn’t require personal interpretation
Specific: Clearly defined; anyone can agree whether or not a standard was met
Reliability: Is a measure consistent and repeatable? Does it always produce the same results? Ex- A scale
Test-ReTest Reliability: Multiple applications over time should yield consistent results
Inter-Rater Reliability: Different observers agree on how the measure should be applied in the same cases.
Validity: Does the measure accurately represent the concept it is supposed to measure? Ex- How can we measure prejudice
Face Validity: The measurement appears reasonable at a first glance; it appears to be measuring what it says it does
Content Validity: The measurement contains all critical elements of the measured concept
Convergent Validity: The measure is related to existing measures of the same concept
Predictive Validity: The measure is related to related outcomes
Response Bias: People/actors cannot or will not provide accurate data
Social Desirability Bias: Individuals/actors lie to avoid social costs
Recall Bias: where people misremember, forget, or change details about past experiences when asked in a study
Agreement Bias: Respondents (inadvertently) choose positively worded options
Central Tendency Bias: Individuals/actors avoid responding in extreme ways
Random Response Bias:Respondents dont know the answer but guess/speculate anyways
Item non-response bias: Individuals skip specific questions/measures frequently (from confsuion)
Tutorial 5- dplyr commands
Select(): Identifies columns to keep or drop(variables)
Filter(): Identifies rows to keep or drop. filters subsets (rows), allows us to subset/ select a smaller portion of data.
Arrange(): Reorders rows based on their value in some columns
Mutate(): Adds or changes columns
Rename: renames columns
Group_by(): groups the data. if you group_by() and then use %>%, any operations on the next line of code will be performed separately for whatever variable you group_by
Summarize(): summarises (or aggregates) data
%>% (Pipe Operator): Links multiple dplyr commands in a row. Ensures you do not have to specify your data frame every time.
Tutorial 6-
Discrete Variables: Can only take on specific values (and usually not many). Nominal and ordinal measures. Always logical, character, and factor classes in R. Boolean variables are always discrete.
Continuous Variables: Can take on many values (and usually partial values), always numeric class Ex- income range 0-250,000 or range of ages 18-95
X-axis: Shows possible values for the variable we want to summarize
Y-axis: Shows how common each value is in the dataset
Histogram: Puts a single continuous variable in “bins" and then shows how common each bin is (letting us look at the distribution) plot information for a single variable. Typically used for continuous variables.
Bar Graphs: Shows how common each value of a discrete variable is.
Density plot: gives us approx the same info as histogram, presents the information as proportions of values represented as a smoothed line.
Center of distribution: Refers to its peak(s) and where it is or they are located
Unimodal: One distinct peak
Bimodal: Two peaks
Multimodal: More peaks
Right-skewed: The long tail is on the right (positive skew)
Left-skewed: The long tail is on the left (negative skewed) very rare.