MANE 3332.03
Lecture 15, March 13
Agenda
- Continue Chapter 4
- Today's Topics: R, Midterm Review, Quiz announcement
- Tech Report One Assignment (assigned 3/6/2025, due 4/3/2025)
Handouts
R in MANE 3332.04
- This is the third time that R is included in MANE 3332
- Currently (and this could change) there will be no assignments in R
- Examples of R will be included in lectures and handouts as covered in class
- The Grade data shown in this lecture are from Spring 2024
- R can be installed on your laptop or run through UTRGV Vlabs
What is R?

The R Project

RStudio

RStudio IDE

UTRGV vLabs

Link to vLabs
R Markdown
R Markdown, part 2

R Markdown, part 3

Markdown Guide

Creating First R Markdown Project
Create A New Project
-
Two Methods
- File, New Project
- Click on New Project Icon
-
In general, we use a new directory

Project Type Selection
We want to create a New Project

Create New Project
The Directory Name and location must be specified

Blank Project

Create RMarkdown File

New R Markdown Form
- Give title for the R Markdown document in the Title field
- Add your name as the author
- My preference is to click on the check box below the Date field to use the current date
- Select Word as the Default Output Format. PDF requires additional software to be installed. You can always export to PDF from Word.

IDE View

YAML
Yet another markup language(YAML) is contained between the dashed lines. It stores the document definition.

R Code
R Code is displayed in the grey box. R Code snippets have the structure of
```{r}
```

Markdown
Markdown codes appear in lines 12 - 16 of the file. A separate module will cover Markdown

More R Code and Markdown

Knitting a Document
Knitting is the process of create the output document from the YAML block, Markdown code and R code.

Save File

Results of Knitting
- Output appears in Console area (lower left pane)
- File list is updated and include a Word Document
- File area contains updated information (lower right pane)
R Demonstration
- Creating and knitting default document
Data Creation
Two primary methods + c() functon + Import Excel
C Function
- R Code
x<- c(1.1,2.2,3.3)
print(x)
- Demonstration
C Function Output

Import Excel Spreadsheet
- Requires readxl
- Not part of standard distribution and must be imported
- First import into R Studio
- Add import code to R Markdown package
Import into R Studio

- Click on Import Dataset
R Studio - Import Dataset

- From Menu, click on "From Excel..."
R Studio - Import Dataset
- Enter File/URL
- Notice preview
- Copy Code Preview in lower right corner
- Click on Import

R Studio - Import Dataset
- Dataset is currently in R Studio but not R Markdown

Importing an Excel Dataset
- Add Code Preview lines in R chunk
- Knit document or run R chunk
library(readxl)
midterm <- read_excel("/Volumes/NO NAME/midterm.xlsx")
View(midterm)
- Demonstration
Import Packages
- Click on Packages (Lower right corner)
- If not present, click on Import

Import Packages, continued

Numerical Summaries
- Called Descriptive Statistics in Chapter 6
- Descriptive statistics help us understand the location or central tendency of data and the scatter or variability in data
- Included in all statistical software packages, R does a good job calculating descriptive statistics
Central Tendency
-
Ostle, et. al. (1996) define central tendency as "the tendency of sample data to cluster about a particular numerical value"
-
Population mean
- Sample mean
-
Sample median - middle value
-
Sample mode - most commonly occuring number(s)
Measures of Variability
-
There are several statistics that measure the variability or spread present in data
-
Population variance
- Sample variance
- Shortcut (Computational) Formula
- Standard deviation is often used because it is measured in the original units
R Function Summary - Data Frame
summary(midterm)

R Function Summary - Variable
summary(midterm$MidtermExam)

R Function Describe
- Summary() does not report variability
- Describe() has to be imported
- Describe() is part of the package psych
library(psych)
describe(midterm)

Describe Output, part 2
