Econometrics

Introduction to R and Positron Installation

  • Start Time: 11:00

  • Speaker Confirmation: Natalie can hear us.

Installing R

  • R Overview:

    • R is a statistical programming language used for data analysis and related tasks.

    • Comes equipped with basic coding tools but lacks advanced features.

  • Installation Steps:

    • Open a web browser (Chrome or Google).

    • Type "download R" in the search bar.

    • Select the latest version from the R download page.

    • Download the R installer file and execute it.

    • Default installation settings are typically adequate.

    • Click "Install" to complete the installation.

Installing Positron

  • Positron Purpose:

    • An enhanced interface for R, providing a streamlined coding environment.

  • Installation Steps:

    • Search "download Positron" in the browser.

    • Go to the download page for Positron (positron.posit.co).

    • Agree to the terms and choose an installation type:

    • User Level Install:

      • Does not require administrative privileges and installs for individual use.

    • System Level Install:

      • Requires administrative privileges, installs for all users on the computer.

      • Not necessarily beneficial for personal use.

    • Check the boxes to add options:

    • "Add open with Positron action to Windows file context menu."

    • "Add to directory context menu."

    • Complete installation and start Positron.

Positron Interface Overview

  • Initial Load:

    • Upon first opening Positron, it may take time to load R and optionally Python if installed.

    • Display includes various panels: Console, Terminal, Problems, Debug Code, Output, Ports.

    • Focus on the Console panel for code execution.

  • Console:

    • Interactive space to execute R code with immediate feedback.

    • Example: To print a message, use print("Hello World").

  • Session Information:

    • Information about the active session and variables will be displayed.

    • Right panel provides variable and plot information.

  • File Explorer:

    • Top panel is the file explorer; can show various directories.

Essential Features in Positron

  • Initial Setup Tips:

    • Do not enable the Positron assistant immediately; can be enabled later.

    • Create a dedicated folder for class materials, e.g., "econometrics" folder in Documents or on Desktop.

  • Accessing Functions:

    • Use "Open with Positron" from the right-click context menu for quick access to files.

Introduction to R Programming

  • R Programming Basics:

    • Understanding the interface is critical for effective usage.

    • Expect to learn a high volume of information rapidly, akin to a cheat sheet.

Data Management in R

  • Downloading Data:

    • Data folders will be provided for each module (e.g., height and wages data).

    • Address issues related to the file path by ensuring file extensions are visible.

  • Loading Data:

    • Use the load function to import datasets, e.g., load("height_wages_data.rdata").

    • Errors may appear if files are misnamed or paths are incorrect; correct and retry.

  • Viewing Data:

    • Use head(data) to view the first few rows, or tail(data) for the last rows.

    • Use View(data) for a graphical table overview (ensure correct capitalization).

Conducting Data Analysis

Descriptive Statistics

  • Mean and Standard Deviation Calculation:

    • Compute using mean(datavariable,na.rm=TRUE)</code>toignoreNAvaluesincalculations.</p></li></ul></li><li><p><strong>SummarizingData</strong>:</p><ul><li><p>Use<code>summary(data)</code>foracompactoverviewofstatisticsincludingmin,max,quartiles,andNAcounts.</p></li></ul></li></ul><h4id="2ff11691−4b33−44ad−85a6−d491727367ba"data−toc−id="2ff11691−4b33−44ad−85a6−d491727367ba"collapsed="false"seolevelmigrated="true">CreatingFrequencyTables</h4><ul><li><p><strong>FrequencyTables</strong>:</p><ul><li><p>Usethe<code>table(datavariable, na.rm=TRUE)</code> to ignore NA values in calculations.</p></li></ul></li><li><p><strong>Summarizing Data</strong>:</p><ul><li><p>Use <code>summary(data)</code> for a compact overview of statistics including min, max, quartiles, and NA counts.</p></li></ul></li></ul><h4 id="2ff11691-4b33-44ad-85a6-d491727367ba" data-toc-id="2ff11691-4b33-44ad-85a6-d491727367ba" collapsed="false" seolevelmigrated="true">Creating Frequency Tables</h4><ul><li><p><strong>Frequency Tables</strong>:</p><ul><li><p>Use the <code>table(datacategorical_variable) to count occurrences in categorical data.

    • Bivariate tables include two variables for cross-tabulation.

Visualizing Data

  • Plotting:

    • Use plot(x=dataxvariable,y=datax_variable, y=datay_variable) to create visual representations of data.

    • Utilize arguments like main="Title", xlab="X Axis Label", and ylab="Y Axis Label" for clarity.

    • Add regression lines with abline(lm(y~x)) to illustrate trends in data.

Subsetting Data

  • Subsetting:

    • Condition-based data selection can be done using logical statements, e.g., data[data$variable < value, ].

    • Combine conditions with & (and) and | (or) to filter datasets effectively.

General Coding Practices

  • Comments in Code:

    • Use # to denote comments for clarity and record-keeping within scripts.

  • Script Management:

    • Create R scripts ending with .r to save and maintain code persistently between sessions. Use Ctrl + S to save.

Common Errors and Issues

  • Interpreting Error Messages:

    • Red text in console indicates errors; read messages carefully to identify issues.

    • Check file paths and names if files cannot be loaded or found.

Final Remarks

  • Questions encouraged throughout, especially around installations or code execution issues.

  • Note deadlines for assignments: Homework due Monday, Chapter 2 due in one additional week.

  • Attendance is vital for the introduction of report topics.