[Solved] CptS 575 Assignment 3

$25

File Name: CptS_575__Assignment_3.zip
File Size: 207.24 KB

SKU: [Solved] CptS 575 – Assignment 3 Category: Tag:
5/5 - (1 vote)

This assignment has two questions. You are encouraged to use R Markdown to generate your report (in PDF).

Question 1. For this question you will be using either the dplyr package from R or the Pandas library in python to manipulate and clean up a dataset called msleep (mammals sleep) that is available on the course webpage at

https://scads.eecs.wsu.edu/wp-content/uploads/2017/10/msleep_ggplot2.csv

The dataset contains the sleep times and weights for a set of mammals. It has 83 rows and 11 variables. Here is a description of the variables:

Name Description
name common name
genus taxonomic rank
vore carnivore, omnivore or herbivore?
order taxonomic rank
conservation the conservation status of the mammal
sleep_total total amount of sleep, in hours
sleep_rem rem sleep, in hours
sleep_cycle length of sleep cycle, in hours
awake amount of time spent awake, in hours
brainwt brain weight in kilograms
bodywt body weight in kilograms

Load the data into R or Python, and check the first few rows for abnormalities. You will likely notice several. All of the tasks in this assignment can be hand coded, but the goal is to use the functions built into dplyr or Pandas to complete the tasks. Suggested functions for Python will be shown in blue while suggested R functions are shown in red. Note: if you are using Python, be sure to load the data as a Pandas DataFrame.

Below are the tasks to perform. Before you begin, print the first few values of the columns with a header including sleep. (head(), head())

  1. Count the number of animals which weigh under 50 kilograms and sleep more than 16 hours a day. (filter(), query())
  2. Print the name, order, sleep time and bodyweight of the animals with the 5 longest sleep times, in order of sleep time. (select(), arrange(), loc(), sort_values())
  3. Add two new columns to the dataframe; wt_ratio with the ratio of brain size to body weight, rem_ratio with the ratio of rem sleep to sleep time. If you think they might be useful, feel free to extract more features than these, and describe what they are. (mutate(), assign())

1

  1. Display the average, min and max sleep times for each order. (group_by(), summarise(), groupby(), agg())
  2. Impute the missing brain weights as the average wt_ratio for that animals order times the animals weight. Make a second copy of your dataframe, but this time impute missing brain weights with the average brain weight for that animals order. What assumptions do these data filling methods make? Which is the best way to impute the data, or do you see a better way, and why? You may impute or remove other variables as you find appropriate. Briefly explain your decisions. (group_by(), mutate(), groupby(),assign())

Question 2. For this question, you will first need to read section 12.6 in the R for Data Science book, here (http://r4ds.had.co.nz/tidy-data.html#case-study). Grab the dataset from the tidyr package (tidyr::who), and tidy it as shown in the case study before answering the following questions. Note: if you are using pandas you can perform these same operations, just replace the gather() function with melt() and the spread() function with pivot(). However, you may prefer to use R for this question, as the dataset is from an R package.

  1. Explain why this line

> mutate(key = stringr::str_replace(key, newrel, new_rel))

is necessary to properly tidy the data. What happens if you skip this line?

  1. How many entries are removed from the dataset when you set na.rm to true in the gather command (in this dataset)?
  2. Explain the difference between an explicit and implicit missing value, in general. Can you find any implicit missing values in this dataset, if so where?
  3. Looking at the features (country, year, var, sex, age, cases) in the tidied data, are they all appropriately typed? Are there any features you think would be better suited as a different type? Why or why not?
  4. Explain in your own words what a gather operation is, and give an example of a situation when it might be useful. Do the same for spread.
  5. Generate an informative visualization, which shows something about the data. Give a brief description of what it shows, and why you thought it would be interesting to investigate.
  6. Suppose you have the following dataset called siteDemo:
Site U30.F U30.M O30.F O30.M
facebook 32 31 60 58
myspace 1 5 3 6
snapchat 6 4 3 2
twitter 17 23 12 17

You know that the U30.F column is the number of female users under 30 on the site, O30.M denotes the number of male users 30 or older on the site, etc. Construct this table, and show the code you would use to tidy this dataset (using gather(), separate() and mutate() or melt(), pivot(), and assign()) such that the columns are organized as: Site, AgeGroup, Gender and Count.

2

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CptS 575 Assignment 3
$25