Data Selection, Univariate Visualization, and Implementation in R

Dataset Selection and Methodological Requirements

  • Required Dataset Information:
    • Dataset Name: The explicit title or formal identifier of the dataset.
    • Access Source: A direct URL or web link to the data repository. If no direct link exists, specific step-by-step navigation instructions on how to locate and retrieve the dataset must be provided.
    • Data Collector / Originator: Identifying the entity, institution, or researchers responsible for collecting the data. Evaluating data originators ensures that the collecting body possesses methodological expertise, implements sound measurement strategies, minimizes systemic bias, and maintains high standards of data integrity.
    • Nature of Data: Explicit identification of whether the data is observational or survey-based:
    • Observational data constitutes the majority of selected datasets.
    • Survey data must be preexisting; independent data collection is not permitted within the scope of the course.
    • Sample Size (NN): The total number of observations, represented formally as N=number of rows / observationsN = \text{number of rows / observations}. This metric is critical for identifying statistical power and sample structure.
    • Scholarly Precedent: Evidence of prior use in academic literature. Datasets should be investigated on Google Scholar to observe how published peer-reviewed studies describe the dataset, operationalize its variables, and document methodology.
    • Codebook Availability: Verification of a formal codebook. The codebook documents measurement levels and coding schemes, which dictate the appropriate statistical tests to conduct.
    • Handling of Missing Data: Documentation of how missing observations are encoded within the raw data matrix (e.g., standard system designations such as NA, or specific numerical missing codes such as −9-9).
    • Timeframe and Collection Date: The exact date or longitudinal period during which data collection took place. Temporal context is essential, as measurement dynamics and sociopolitical environments shift significantly across eras.

Longitudinal Data Structure and Multi-Wave Surveys

  • American National Election Studies (ANES) Context:
    • Temporal variation drastically alters survey content and structure; for example, the ANES from 20242024 contains fundamentally different questions, cultural contexts, and measurement frameworks than the ANES from 19481948.
    • ANES utilizes a multi-wave collection design comprising two distinct phases: pre-election and post-election waves.
  • Variable Alignment Across Survey Waves:
    • Enduring Traits: Independent and dependent variables may be drawn from different waves only if the variable represents a stable, enduring characteristic. For example, demographic attributes such as gender identity collected in the pre-election wave do not typically shift and can legitimately be paired with a post-election dependent variable such as presidential vote choice.
    • Dynamic / Time-Varying Traits: Variables that are subject to temporal fluctuation—such as intended vote choice or presidential approval ratings—should not be paired across differing waves. Theoretical misalignment occurs when pre-election opinions are matched against post-election evaluations, as external campaign events and election outcomes alter perception between waves.
    • Methodological Best Practice: Unless an independent variable is an enduring, immutable trait, both the independent variable (IVIV) and dependent variable (DVDV) should be derived from the exact same wave (either entirely pre-election or entirely post-election).

Assignment Parameters and Research Support

  • Submission Logistics:
    • Deadline: Friday at 07:0007:00.
    • Multiple Dataset Proposals: Submission of two or three potential candidate datasets is permissible if feedback is needed to select the optimal data source.
    • Office Hours and Consultation: Dedicated support is available during Wednesday office hours or via direct contact.
    • Data Assistance: Direct guidance is available for locating and extracting datasets if initial searches fail; extensions of one day can be requested in advance if additional preparation time is required.

Computational Environment and Setup in R

  • Session Initialization and Package Loading:
    • Packages must be loaded into the active library session using script chunks prior to executing visualization routines.
    • If an R session has been closed or interrupted, all preceding code chunks must be re-executed in sequential order to restore active workspace objects.
  • Reproducibility and Random Seeds:
    • Setting a pseudorandom number generator seed guarantees identical outputs across independent computational runs.
    • Standard default seed parameter: set.seed(42).
    • Alternate customized seed parameter used for comparison: set.seed(20).
  • Data Frame Construction:
    • Rebuilding or importing the primary data frame object into the global environment is required before attempting plotting routines.

Univariate Graphical Displays and Distributional Metrics

  • Univariate Visualization Functions: Graphical representations focused strictly on single-variable analysis, serving as the required display format for independent and dependent variables.
  • Histograms:
    • Variable Type: Applied exclusively to continuous or discrete numeric variables.
    • Mechanism: Aggregates continuous numeric data along the horizontal xx-axis into discrete contiguous intervals ("bins").
    • Vertical Axis Metric: The vertical yy-axis represents absolute frequency (raw count of observations falling within each specific bin interval).
  • Kernel Density Plots:
    • Variable Type: Applied to continuous numeric variables.
    • Mechanism: Generates a smoothed, continuous estimate of the underlying probability distribution function.
    • Vertical Axis Metric: The vertical yy-axis represents relative probability density rather than raw frequency counts.
  • Bar Graphs:
    • Variable Type: Applied exclusively to discrete categorical or factor variables.
    • Mechanism: Displays distinct, non-contiguous (separated) rectangular bars corresponding to nominal or ordinal categories.
    • Vertical Axis Metric: The vertical yy-axis represents the total count of observations within each distinct category.
  • Summary Comparison of Vertical (yy-Axis) Metrics:
    • Kernel Density: density (y=relative probability densityy = \text{relative probability density}
    • Histogram: frequency (y=bin frequency countsy = \text{bin frequency counts}
    • Bar Graph: count (y=category total countsy = \text{category total counts}

Implementing Bar Plots and Factor Recoding in R

  • Bar Graph Aesthetics in ggplot2:
    • Geometric Object: Implemented via geom_bar().
    • Bar Fill Color: Specified using "sky blue".
    • Bar Outline / Border Color: Specified using "black".
    • Plot Labels (labs specifications):
    • Plot Title: "Bar Graph Categories"
    • Horizontal Axis Label (xlab): "Categorical Variable"
    • Vertical Axis Label (ylab): "Count"
    • Formatting Mandates: All titles, axis labels, and captions must use formal capitalization, complete descriptions, and correct spelling.
  • Categorical Mapping and Vector Definitions:
    • Raw categorical observations frequently contain placeholder letter codes (a, b, c) that require substantive re-labeling for interpretability.
    • Definitional Mapping:
    • a maps to "important"
    • b maps to "not important"
    • c maps to "slightly important"
    • Vector Syntax in R:
    • Character elements must strictly be enclosed within quotation marks (e.g., "important"), otherwise R interprets the input as an undefined variable object and terminates with an execution error.
    • Vector definition syntax: custom_labels <- c(a = "important", b = "not important", c = "slightly important").
    • Punctuation Rules: Commas must separate each element within the c() function; trailing commas after the final element are syntactically invalid and cause parsing errors.
    • Incorporating Custom Scales: The custom vector is passed directly into the visualization scale pipeline to override default alphanumeric factor levels while preserving existing aesthetic configurations.