F01.justanswer.com



---title: "PSYC70-20S-W03-H1 Data Wrangling Homework"author: "YOUR NAME and STUDENT NUMBER"output: html_document---```{r setup, include=FALSE}knitr::opts_chunk$set(echo = TRUE)```## Before starting lets check:1. The `.csv` files are saved into a folder on your computer (or RStudio Cloud) and you have manually set this folder as your working directory (if required). 2. The `.Rmd` file is saved in the same folder as the `.csv` files.## Load in the data1. You see the code chunk called `libraries` below. It is all set-up to load in the data for you and to call `tidyverse` to the `library()`. Run this code chunk now to bring in the data and tidyverse. You can do this in the console, in a script, or even through the code chunk by clicking the small green play symbol in the top right of the code chunk.```{r libraries, echo = FALSE, warning=FALSE, message=FALSE}library("tidyverse")screening <- read_csv("p_screen.csv")responses <- read_csv("QHC_responses.csv")scoring <- read_csv("QHC_scoring.csv")```## The TasksNow that we have the data loaded, tidyverse attached, and have viewed our data, you should now try to complete the following 9 tasks. You may want to practice them first to get the correct code and format, and to make sure they work. You can do this in the console or a script, but remember, once you have the correct code, edit the necessary parts of this `.Rmd` file to produce a reproducible Rmd file. In short, go through the tasks and change only the `NULL` with what the question asks for and then make sure that the file `knits` at the end so that you have a fully reproducible code.When altering code inside the code blocks, *do not* re-order or rename the code blocks (T1, T2, ... etc.).### Task 1 - Oldest ParticipantReplace the `NULL` in the `T1` code chunk with the Participant ID of the oldest participant. Store this single value in `oldest_participant` (e.g., `oldest_participant <- 999`).```{r T1}# hint: look at your data, who is oldest?oldest_participant <- NULL```### Task 2 - Arranging D-SPANReplace the `NULL` in the `T2` code chunk with code that arranges participants' D-SPAN performance from highest to lowest using the appropriate one-table dplyr (i.e., Wickham) verb. Store the output in `cogtest_sort`. (e.g. `cogtest_sort <- verb(data, argument)`)```{r T2}# hint: arrange your screening datacogtest_sort <- NULL```### Task 3 - Foreign Language SpeakersReplace the `NULL` in each of the two lines of code chunk `T3`, so that `descriptives` has a column called `n` that shows the number of participants that speak a foreign language and number of participants that do not speak a foreign language, and another column called `median_age` that shows the median age for those two groups. If you have done this correctly, `descriptives` should have 3 columns and 2 rows of data, not including the header row.```{r T3}# hint: First need to group_by() foreign languagescreen_groups <- NULL# hint: second need to summarise(). Pay attention to specific column names given.descriptives <- NULL```### Task 4 - Creating Percentage MOCA scoresReplace the `NULL` in the `T4` code chunk with code using one of the dplyr verbs to add a new column called `MOCA_Perc` to the dataframe `screening` In this new column should be the `MOCA` scores coverted to percentages. The maximum achievable score on MOCA is `30` and percentages are calculated as `(participant score / max score) * 100`. Store this output in `screening`.```{r T4}# hint: mutate() something using MOCA and the percentage formulascreening <- NULL```### Task 5 - Remove the MOCA columnNow that we have our MoCA score expressed as a percentage `MOCA_Perc` we no longer need the raw scores held in `MOCA`. Replace the `NULL` in the `T5` code chunk using a one-table dplyr verb to keep all the columns of `screening`, with the same order, but without the `MOCA` column. Store this output in `screening`.```{r T5}# hint: select your columnsscreening <- NULL```### Task 6 - Gather the Responses togetherReplace the `NULL` in the `T6` code chunk using code to gather the responses to all the questions of the QHC from wide format to tidy/long format. Name the first column `Question` and the second column `RESPONSE`. Store this output in `responses_long`. ```{r T6}# hint: gather the question columns (Q1:Q15) in responsesresponses_long <- NULL ```### Task 7 - Joining the dataNow we need to join the number of points for each response in `scoring` to the participants' responses in `responses_long`. Replace the `NULL` in the `T7` code chunk using `inner_join()` to combine `responses_long` and `scoring` into a new variable called `responses_points`. ```{r T7}# hint: join them by the column common to both scoring and responses_longresponses_points <- NULL```### Task 8 - Working the PipesBelow we have given you a code chunk with 5 lines of code. The code takes the data in its current long format and then creates a QHC score for each participant, before calculating a mean QHC score for the two groups of participants - those that play musical intruments and those that don't - and stores it in a variable called `musical_means`.```participant_groups <- group_by(responses_points, ID)participant_scores <- summarise(participant_groups, Total_QHC = sum(SCORE))participant_screening <- inner_join(participant_scores, screening, "ID")screening_groups_new <- group_by(participant_screening, MUSICAL)musical_means <- summarise(screening_groups_new, mean_score = mean(Total_QHC))```Replace the `NULL` in the `T8` code chunk with the following code converted into a fuctioning pipeline using pipes. Put each function on a new line one under the other. This pipeline should result in the mean QHC values of musical and non-musical people stored in `musical_means` which should be made of two rows by two columns. ```{r T8}# hint: in pipes, the output of the previous function is the input of the subsequent function.# hint: function1 %>% function2musical_means <- NULL```### Task 9 - Difference in Musical MeansFinally, replace the `NULL` in the `T9` code chunk with a single value, to two decimal places, that is the value of how much higher the QHC score of people who play music is compared to people who don't play music (e.g., 2.93)```{r T9}# hint: look in musical means and enter the difference between the two means.QHC_diff <- NULL```## Finished - Don't forget to save and submit this file on Quercus as Homework 1. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download