Overview

This file contains a set of tasks that you need to complete in R for the lab assignment. The tasks may require you to add a code chuck, type code into a chunk, and/or execute code. In this lab you will also need to describe your results. Don’t forget that you need to acknowledge if you used any resources beyond class materials or got help to complete the assignment.

Instructions associated with this assignment can be found in the file “InstructionsDescribingData.html”. You can find the code book associated with the BBQ data on the AsULearn page under week 2.

The data set you will use is different than the one used in the instructions. Pay attention to the differences in the Excel files name, any variable names, or object names. You will need to adjust your code accordingly.

Once you have completed the assignment, you will need to knit this R Markdown file to produce an html file. You will then need to upload the .html file and this .Rmd file to AsULearn.

1. Add your Name and the Date

The first thing you need to do in this file is to add your name and date in the lines underneath this document’s title (see the code in lines 9 and 10).

2. Identify and Set Your Working Directory

You need to identify and set your working directory in this section. If you are working in the cloud version of RStudio, enter a note here to tell us that you did not need to change the working directory because you are working in the cloud. getwd() setwd(“/Users/Kaydence/Desktop/Research Methods Lab/Decribing_Data”)

3. Installing and Loading Packages and Data Set

You need to install and load the packages and data set you’ll use for the lab assignment in this section. In this lab, we will use the three packages we have used in previous labs (dplyr, tidyverse, and openxls) and one new package (modeest). Remember, the first time you use a package you need to install the package.

install.packages("dplyr")
## 
## The downloaded binary packages are in
##  /var/folders/dj/s8c5y9n511x0wx_4j339dln00000gn/T//RtmpJLa9eE/downloaded_packages
library("dplyr")
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
install.packages("tidyverse")
## 
## The downloaded binary packages are in
##  /var/folders/dj/s8c5y9n511x0wx_4j339dln00000gn/T//RtmpJLa9eE/downloaded_packages
library("tidyverse")
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.5
## ✔ ggplot2   3.5.1     ✔ stringr   1.5.1
## ✔ lubridate 1.9.4     ✔ tibble    3.2.1
## ✔ purrr     1.0.4     ✔ tidyr     1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
install.packages("modeest")
## 
## The downloaded binary packages are in
##  /var/folders/dj/s8c5y9n511x0wx_4j339dln00000gn/T//RtmpJLa9eE/downloaded_packages
library("modeest")
install.packages("openxlsx")
## 
## The downloaded binary packages are in
##  /var/folders/dj/s8c5y9n511x0wx_4j339dln00000gn/T//RtmpJLa9eE/downloaded_packages
library("openxlsx")
library(readxl)
Assignment6_data <- read_excel("Assignment6_data.xlsx")
head(Assignment6_data,5)
## # A tibble: 5 × 14
##   Observation   Sex   Age Hometown `Favorite Meat` `Favorite Sauce` Sweetness
##         <dbl> <dbl> <dbl>    <dbl>           <dbl>            <dbl>     <dbl>
## 1           1     2    21        4               2                3         4
## 2           2     2    18        7               3                6         2
## 3           3     1    20        7               5                3         3
## 4           4     2    20        4               5                6         5
## 5           5     1    22        6               4                2         3
## # ℹ 7 more variables: `Favorite Side` <dbl>, `Restaurant City` <chr>,
## #   `Restaurant Name` <chr>, `Minutes Driving` <dbl>, `Sandwich Price` <dbl>,
## #   `Dinner Plate Price` <dbl>, `Ribs Price` <dbl>

4. Names of Variables

Display the names of the variables in your data set.

names(Assignment6_data)
##  [1] "Observation"        "Sex"                "Age"               
##  [4] "Hometown"           "Favorite Meat"      "Favorite Sauce"    
##  [7] "Sweetness"          "Favorite Side"      "Restaurant City"   
## [10] "Restaurant Name"    "Minutes Driving"    "Sandwich Price"    
## [13] "Dinner Plate Price" "Ribs Price"

5. Look at data

Display the last 5 observations in the data set.

tail(Assignment6_data, 5)
## # A tibble: 5 × 14
##   Observation   Sex   Age Hometown `Favorite Meat` `Favorite Sauce` Sweetness
##         <dbl> <dbl> <dbl>    <dbl>           <dbl>            <dbl>     <dbl>
## 1         644     1    19        1               1                4         1
## 2         645     1    38        7               6                5         2
## 3         646     2    20        2               2                7         2
## 4         647     1    44        4               2                7         2
## 5         648     2    22        1               5                5         2
## # ℹ 7 more variables: `Favorite Side` <dbl>, `Restaurant City` <chr>,
## #   `Restaurant Name` <chr>, `Minutes Driving` <dbl>, `Sandwich Price` <dbl>,
## #   `Dinner Plate Price` <dbl>, `Ribs Price` <dbl>

6. Look at one variable

Choose one variable other than Dinner.Plate.Price and display all the observations for that variable.

print(Assignment6_data$`Sandwich Price`)
##   [1] 20 12  5 23 22  5 15 16 15 22 20 15 22 15 30 20 15 16 25 15 15 11  7 10 10
##  [26] 12  9 11 16 12  6 20 15 12 15 14 20 10 16 12 10 14 20 12  8  8  8  7  9  6
##  [51]  7  6  5 15 20 15 10 15 10 15 10 20 15 20  8 20 15 12 10 16  5 10  8  8  1
##  [76] 10 20 15 15 18 10 10 12 15 10 20 22 15 20 20 10 10 12 26 13  5 10 10 10 10
## [101] 13 69 15 15 13 10 15 25  8 13 15 10 20 25 10 20 13  3  3 12  3 13 40 15 12
## [126]  8 14 16 15 12 15 20 20 15 50 15 18 15 15  8  9 15 15 12 23 15 12 15 15 15
## [151] 12 13  0  5 14 12 12 20 24 22 11 15 12 15 13  8 10  9  9 13 10  9 13 17 20
## [176] 12 10 15 15 26 15  6 18 25 25 22  7 10 13 20 20  5  0 13 18 10 12 16 15 15
## [201]  0 20 16 15 18 10 15 14 15 10 15 15 15 15 15 12 15 10 10 15 10 14 10  1 10
## [226]  9 25 10 20 12 15 12 12 15  8  7  0 13 15  8  0 12 15 12 15 12 15 15 10 16
## [251] 20  6 22 10 25 16  8 15 30 12 20  6 15  8 20 10  0 15 16 NA  0  4 NA 15 15
## [276] 18 12 20 12 15  9 20 NA 25 25 12 10 15 15 20 16 14 10 15 16 12 30 12 24 25
## [301] 30  8 20 12 22 10 14 16 12 10 20 12 10 12 12  8 12 12 10 25 20 22 20 18  5
## [326]  5 10  6 14  6 11 12 10 10 15 15 15 20 20 15 15 26 12 10 15 10 30 30 15 14
## [351] 20 12 22 15 12 20  2  6 15 20  3 14  8  8 13 27 25 10 10 10 15 10 15 15 12
## [376]  0 10 15 30 10 10 15  7 12 15 15 14  9 10 12 10 10 22 14 13 10 12 20 10 10
## [401] 15 10 14 12  9 16 12 18 20 18 15 15 15  6  7 15 10 25 11 10  8 10 10 12  9
## [426] 18  0 20 13 15 10  9 20 12 NA NA NA NA NA NA NA NA NA NA NA NA NA NA 15 17
## [451] 20 15 15  7 10  8 15 20 10  9 25 15 10 29 10 15 14 26 10 14 12 27 10 14 15
## [476] 15 22 15 10  0 15 15 13 10 14 12 15 10 10 15 40 16 11 10 15 16 10 15  6 20
## [501] 11 35 17 14 15 18 12 20 25 20 45 24 30 16  9 22 15 15 18 22 18 16 20 14 22
## [526] 13 20 12 NA 23 15 10 16 22  0 18 10 15 20 10 10 10 15 10 15 NA 15 14 20 10
## [551] 13 20 14 15 20 15 15 12 18 30 NA 20 15 12 10 10 12  7 16 15 15 10  8 12 10
## [576] 18 NA 20 10 14 12 15 24 15 15 22 12 17 12 15 18 20 22 16 15 15 15 15 12 15
## [601] 12 15 12 13 12 10 20  8 10 10 13 20 10 14 10 19 18 14 15 30 20 15 16 16 30
## [626] 10 13 10 20 15  5 26  6 10 20 30 12 15 15 20  7 22 NA  0 25 20  8 40

7. Means

You need to calculate the means for variables measuring 1) the price of a dinner plate, 2) preferred sweetness of sauce, 3) how long the respondent is willing to drive, and 4) the price of a rib plate. Calculate the means of each variable separate chunks of code (that is, you’ll need four distinct chunks of code). After each chunk of code, write a one sentence description of the mean. Don’t forget about missing data.

mean(Assignment6_data$`Dinner Plate Price`, na.rm =TRUE)
## [1] 19.74563

The mean amount of money respondents are willing to pay for a dinner plate is 19.74563 dollars.

mean(Assignment6_data$Sweetness, na.rm =TRUE)
## [1] 2.889922

The mean amount of sweetness respondents prefer is 2.88922.

mean(Assignment6_data$`Minutes Driving`, na.rm =TRUE)
## [1] 41.71498

The mean amount of minutes respondents are willing to drive for good bbq is 41.71498.

mean(Assignment6_data$`Ribs Price`, na.rm =TRUE)
## [1] 23.54849

The mean price respondents are willing to pay for a plate of ribs is 23.54849 dollars.

8. Rounding

Recalculate the means, but round the calculated values. Again, use a separate chunk for each rounded mean. After each chunk of code, write a one sentence description of the mean. Don’t forget about missing data. Importantly, you need to round the means of the different variables to different decimal places.

round(mean(Assignment6_data$`Dinner Plate Price`, na.rm=TRUE),digits=2)
## [1] 19.75

The mean amount of money respondents are willing to pay for a dinner plate is $19.75. - Sweetness of sauce should be rounded to the 1st decimal place.

round(mean(Assignment6_data$Sweetness, na.rm=TRUE),digits=1)
## [1] 2.9

The mean amount of sweetness respondents prefer is 2.9. - How long the respondent is willing to drive should be rounded to the 3rd decimal place.

round(mean(Assignment6_data$`Minutes Driving`, na.rm=TRUE),digits=3)
## [1] 41.715

The mean amount of minutes respondents are willing to drive for good bbq is 41.715. - The price of a rib plate should be rounded to the 2nd decimal place.

round(mean(Assignment6_data$`Ribs Price`, na.rm=TRUE),digits=2)
## [1] 23.55

The mean price respondents are willing to pay for a plate of ribs is $23.55. # 9. Medians You need to calculate and describe the medians of the variables measuring 1) age of the respondent, 2) how long the respondent is willing to drive for good BBQ, and 3) the price of a sandwich. Use a separate chunk of code for each variable. After each chunk of code write one sentence description of the median. Don’t forget about missing data.

median(Assignment6_data$`Dinner Plate Price`, na.rm=TRUE)
## [1] 18

It looks like the median price respondents are willing to pay for a dinner plate is $18 dollars.

median(Assignment6_data$Sweetness, na.rm=TRUE)
## [1] 3

It looks like the median sweetness tolerance respondents have is a 3.

median(Assignment6_data$`Minutes Driving`, na.rm=TRUE)
## [1] 30

It looks like the median amount of minutes respondents are willing to drive is 30 minutes.

median(Assignment6_data$`Ribs Price`, na.rm=TRUE)
## [1] 22

It looks like the median price respondents are willing to pay for ribs is $22 dollars.

10. Modes

You need to calculate and describe the modes of the variables for 1) favorite meat, 2) favorite sauce, and 3) favorite side. These are all categorical variables. Use a separate chunk of code for each variable. After each chunk of code write one sentence description of the mode.

When describing these results, you need to convert the numerical modes of the different variables into words according to the survey code book (available on AsU Learn under week 2).

mfv(Assignment6_data$`Dinner Plate Price`)
## [1] 15

The most coomon price respondents are willing to pay for a dinner plate is $15 dollars.

mfv(Assignment6_data$Sweetness)
## [1] 3

The most common sweetness respondents perfer is a 3.

mfv(Assignment6_data$`Minutes Driving`)
## [1] 30

The most common minutes respondents would drive for good bbq would be 30 minutes.

mfv(Assignment6_data$`Ribs Price`)
## [1] NA

11. Ranges, Maximiums, and Minimums

You need to calculate and describe the ranges, maximums, and minimums of the variables that identify respondents’ 1) ages, 2) rib price, and 3) how many minutes they would drive for BBQ. Use a separate chunk of code for each variable. After each chunk of code write one sentence description of the minimum, maximum, and range.

min(Assignment6_data$`Dinner Plate Price`, na.rm=TRUE)
## [1] 0

The minimum amount of money respondents said they would pay for a dinner plate was 0 dollars.

max(Assignment6_data$`Dinner Plate Price`, na.rm=TRUE)
## [1] 69

The max amount of money respondents said they would pay for a dinner plate is $69 dollars.

max(Assignment6_data$`Dinner Plate Price`, na.rm=TRUE) - min(Assignment6_data$`Dinner Plate Price`, na.rm=TRUE)
## [1] 69

The range of prices respondents are willing to pay for a dinner plate is $69 dollars.

min(Assignment6_data$Sweetness, na.rm=TRUE)
## [1] 1

The minimum amout of sweetness respondents would want is 1.

max(Assignment6_data$Sweetness, na.rm=TRUE)
## [1] 5

the maximum amount of sweetness respindents would want is a 5.

max(Assignment6_data$Sweetness, na.rm=TRUE) - min(Assignment6_data$Sweetness, na.rm=TRUE)
## [1] 4

The range of sweetness respondents are willing to have is a 4.

min(Assignment6_data$`Minutes Driving`, na.rm=TRUE)
## [1] 0

The minimum amount of minutes respondents are willing to drive for good bbq is 0.

max(Assignment6_data$`Minutes Driving`, na.rm=TRUE)
## [1] 500

The max amount of minutes respondents are willing to drive for good bbq is 500 minutes.

max(Assignment6_data$`Minutes Driving`, na.rm=TRUE) - min(Assignment6_data$`Minutes Driving`, na.rm=TRUE)
## [1] 500

The range of minutes driving respondents are willing to drive is 500 minutes.

min(Assignment6_data$`Ribs Price`, na.rm=TRUE)
## [1] 0

The minimum price respondents are willing to pay for a rib plate is 0 dollars.

max(Assignment6_data$`Ribs Price`, na.rm=TRUE)
## [1] 75

The max price respondents are willing to pay for a rib plate is 75 dollars.

max(Assignment6_data$`Ribs Price`, na.rm=TRUE) - min(Assignment6_data$`Ribs Price`, na.rm=TRUE)
## [1] 75

The range of prices respondents are willing to pay for a rib plate is 75 dollars. # 12. Standard Deviations You need to calculate and describe the standard deviation of the variables that identify 1) the number of minutes a respondent would drive for BBQ and 2) the price they would pay for a sandwich in this section.

sd(Assignment6_data$`Minutes Driving`, na.rm=TRUE)
## [1] 50.95685

The standard deviation of the minutes driving a respondent is willing to drive for good bbq is 50.96.

sd(Assignment6_data$`Sandwich Price`, na.rm=TRUE)
## [1] 6.608642

The standard deviation of the price respondents are willing to pay for a BBQ Sandwich is $6.61.

13. Did you recieve help?

Enter the names of anyone one that assisted you with completing this lab. If no one helped you complete the assignment, just type out that no one helped you No I did not receive any help on this assignment.

14. Did you provide anyone help with completing this lab?

Enter the names of anyone that you assisted with completing this lab. If you did not help anyone, then just type out that you didn’t help anyone. No I did not give any help on this assignment. # 15. Knit the Document Click the “Knit” button to publish your work as an html document. This document or file will appear in the folder specified by your working directory. You will need to upload both this RMarkdown file and the html file it produces to AsU Learn to get all of the lab points for this week.