Week 5: Learning Log
Downloading Everything
# setting the CRAN mirror
options(repos = c(CRAN = "http://cran.rstudio.com"))
install.packages("rmdformats")##
## The downloaded binary packages are in
## /var/folders/cw/l9bfyrms3md0tbkr1866zbl80000gn/T//Rtmp3Masau/downloaded_packages
library(rmdformats)
library(tidyverse)## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.3 ✓ purrr 0.3.4
## ✓ tibble 3.1.0 ✓ dplyr 1.0.5
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ readr 1.4.0 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(knitr)
library(dplyr)My Coding Goals this Week
My goals this week were to help create the table for our report. Our group has been having trouble reproducing the table, and even though I am a little bit lost everytime I look at the code so far, I am going to try my best to help figure out the table.
I also wanted to finish coding the individual variables from last week. I’m not sure these will be beneficial to my group with the final code, but I mostly did them for my own understanding.
The Tables
There was a correction in our paper for the table with incorrect data. The columns had been switched around (Table 3).
The Corrected Table 3
We also have to reproduce Table 1 and Table 2.
Table 1
Table 2
Our group decided to use the gt package to create our table. The first step was installing this package into R and loading it.
install.packages("gt")##
## The downloaded binary packages are in
## /var/folders/cw/l9bfyrms3md0tbkr1866zbl80000gn/T//Rtmp3Masau/downloaded_packages
library(gt)We are still creating the tibble that will be used to create the table.
Challenges and Successes
This is our current code. Arunima showed me how to create the factors and I attempted to do them all myself. I think it worked out pretty well.
I also tried to use pivot_longer and pivot_wider, and even though I watched Danielle’s modules, I was still quite confused. I put some of my failures here for your enjoyment, and also for future Vic :)
tableone <- alldata %>% pivot_longer(!Ever_covid, names_to = “vars”, values_to = “values”) %>% group_by(Ever_covid, vars, values) %>% count(name = “number”) %>% filter()
alldata %>% pivot_wider( id_cols = NULL, names_from = Ever_covid, values_from = gender, values_fn = length) %>% group_by(alldata$gender)
I might have to search the internet to learn more about pivot_longer and pivot_wider, since I feel like I currently lack a basic understanding oops.
library(haven)
COVID <- read_sav(file ="coviddata.sav")
# data for table 1, creating factors for each variable
alldata <- COVID %>%
select(Ever_covid, gender:region)
alldata <- zap_labels(alldata) %>% mutate_if(is.numeric, as.factor)
alldata$Ever_covid <- factor(alldata$Ever_covid, labels = c("no_covid", "yes_covid"))
alldata$gender <- factor(alldata$gender, labels = c("Male", "Female"))
alldata$age_categories <- factor(alldata$age_categories, labels =c("18 to 24 years", "25 to 34 years", "35 to 44 years", "45 to 54 years", "55 years and over"))
alldata$Has_child <- factor(alldata$Has_child, labels = c("No", "Yes"))
alldata$Working <- factor(alldata$Working, labels = c("Not working", "Working"))
alldata$Key_worker <- factor(alldata$Key_worker, labels = c("No", "Yes"))
alldata$degree <- factor(alldata$degree, labels = c("GSCE/vocational/A-level/No formal qualifications", "Degree or higher (Bachelors, Masters, PhD"))
alldata$region <- factor(alldata$region, labels = c("Midlands", "South & East", "North", "London", "Wales, Scotland and Northern Ireland"))My Coded Variables
I finished off the rest of the variables from last week, but I am yet again not around to coding the ones with broken data (Table 3 variables).
COVID <- read_sav(file ="coviddata.sav")
# not worried at all - covid = 90
worrycovid <- COVID %>%
group_by(q9worry) %>%
filter(Ever_covid == 1, q9worry == 1) %>%
select(Ever_covid, q9worry) %>%
count(Ever_covid)
# not worried at all - no covid = 116
worrynocovid <- COVID %>%
group_by(q9worry) %>%
filter(Ever_covid == 0, q9worry == 1) %>%
select(Ever_covid, q9worry) %>%
count(Ever_covid)
# perceiving risk - no covid = 148 (themselves)
perceiverisknocovid <- COVID %>%
group_by(q10arisk) %>%
filter(Ever_covid == 0, q10arisk == 1) %>%
select(Ever_covid, q10arisk) %>%
count(Ever_covid)
# perceiving risk - covid = 58 (themselves)
perceiveriskcovid <- COVID %>%
group_by(q10arisk) %>%
filter(Ever_covid == 1, q10arisk == 1) %>%
select(Ever_covid, q10arisk) %>%
count(Ever_covid)
# perceiving risk to others - no covid = 45
perceiverisknocovidother <- COVID %>%
group_by(q10brisk) %>%
filter(Ever_covid == 0, q10brisk == 1) %>%
select(Ever_covid, q10brisk) %>%
count(Ever_covid)
# perceiving risk to others - covid = 19
perceiveriskcovidother <- COVID %>%
group_by(q10brisk) %>%
filter(Ever_covid == 1, q10brisk == 1) %>%
select(Ever_covid, q10brisk) %>%
count(Ever_covid)
# did not identify symptoms - no covid = 1729
symptomsnocovid <- COVID %>%
group_by(Sx_covid_nomissing) %>%
filter(Ever_covid == 0, Sx_covid_nomissing == 0) %>%
select(Ever_covid, Sx_covid_nomissing) %>%
count(Ever_covid)
# did not identify symptoms - covid = 788
symptomscovid <- COVID %>%
group_by(Sx_covid_nomissing) %>%
filter(Ever_covid == 1, Sx_covid_nomissing == 0) %>%
select(Ever_covid, Sx_covid_nomissing) %>%
count(Ever_covid)These are the percentages from those variables:
- worry, no covid = 116/4656 = 2.49%
- worry, covid = 90/1493 = 6.03%
- perceiving risk to themselves, covid = 58/1493 = 3.88%
- perceiving risk to others, no covid = 45/4656 = 0.97%
- perceiving risk to others, covid = 19/1493 = 1.27%
- did not identify common symptoms, no covid = 1729/4656 = 37.13%
- didn’t identify common symptoms, covid = 788/1493 = 52.78%
Next Steps…
My next steps are to continue helping with the table and then start answering the questions for our presentation in Week 8.