Dony Indiarto
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Tidy Tuesdays Week 3: College Tuition, Diversity, and Pay <!--[https://www.economist.com/united-states/2016/04/21/delayed-gratification](https://i.imgur.com/6IQUvbF.png)--> To start please visit: https://github.com/BEES-Tidy-Tuesdays/home You will find a link to this collaborative document called "Week 2 notes". :::info **Please Read** :mega: This is a collaborative markdown document: feel free to add, change, and improve it. We will upload the final document to github after this Tidy Tuesday session and use parts of it as a template for future sessions. If something is unclear or doesn't make sense, fix it, or make a comment. ::: ### A. Preparation (~5-10 minutes) #### A1. Make sure R and R studio are installed and running #### A2. Download and start exploring the data Please access the data [here](https://www.tuitiontracker.org/data/download/all-schools.csv). Download and extract to a specified folder. We encourage you to start working by creating a new Rproject, and use best practices for file management. <!--OR To clone the data set from github using git in RStudio: 1. Select "New Project" 2. Select "Version control" 3. Select "Git" 4. Paste "https://github.com/rfordatascience/tidytuesday/tree/master/data/2020/2020-03-10" as the URL, and select where you want to clone the files to on your computer N.B. You need git installed on your computer, you can download it here: - https://gitforwindows.org/ (Windows) - https://git-scm.com/download/mac (Mac) --> OR Just use this code below to download the data: #### OPTION 1 ``` # Get the Data library(tidyverse) tuition_cost <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-10/tuition_cost.csv') tuition_income <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-10/tuition_income.csv') salary_potential <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-10/salary_potential.csv') historical_tuition <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-10/historical_tuition.csv') diversity_school <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-10/diversity_school.csv') ``` #### OPTION 2 ``` # read in with tidytuesdayR package (https://github.com/thebioengineer/tidytuesdayR) # PLEASE NOTE TO USE 2020 DATA YOU NEED TO USE tidytuesdayR version ? from GitHub # Either ISO-8601 date or year/week works! # Install via devtools::install_github("thebioengineer/tidytuesdayR") tuesdata <- tidytuesdayR::tt_load('2020-03-10') tuesdata <- tidytuesdayR::tt_load(2020, week = 11) tuition_cost <- tuesdata$tuition_cost ``` #### OPTION 3 ``` # Raw data from tuitiontracker.org tuition_tracker <- readr::read_csv(https://www.tuitiontracker.org/data/download/all-schools.csv) ``` ### A2. What are the files? What are the variables? #### `tuition_cost.csv` |variable |class |description | |:--------------------|:---------|:-----------| |name |character |School name | |state |character | State name | |state_code |character | State Abbreviation | |type |character | Type: Public, private, for-profit| |degree_length |character | 4 year or 2 year degree | |room_and_board |double | Room and board in USD | |in_state_tuition |double | Tuition for in-state residents in USD | |in_state_total |double | Total cost for in-state residents in USD (sum of room & board + in state tuition) | |out_of_state_tuition |double | Tuition for out-of-state residents in USD| |out_of_state_total |double | Total cost for in-state residents in USD (sum of room & board + out of state tuition) | #### `tuition_income.csv` |variable |class |description | |:-----------|:---------|:-----------| |name |character | School name | |state |character | State Name | |total_price |double | Total price in USD | |year |double | year | |campus |character | On or off-campus | |net_cost |double | Net-cost - average actually paid after scholarship/award | |income_lvl |character | Income bracket | #### `salary_potential.csv` |variable |class |description | |:-------------------------|:---------|:-----------| |rank |double | Potential salary rank within state | |name |character | Name of school | |state_name |character | state name | |early_career_pay |double | Estimated early career pay in USD | |mid_career_pay |double | Estimated mid career pay in USD | |make_world_better_percent |double | Percent of alumni who think they are making the world a better place | |stem_percent |double | Percent of student body in STEM | #### `historical_tuition.csv` |variable |class |description | |:------------|:---------|:-----------| |type |character | Type of school (All, Public, Private) | |year |character | Academic year | |tuition_type |character | Tuition Type All Constant (dollar inflation adjusted), 4 year degree constant, 2 year constant, Current to year, 4 year current, 2 year current | |tuition_cost |double | Tuition cost in USD | #### `diversity_school.csv` |variable |class |description | |:----------------|:---------|:-----------| |name |character | School name | |total_enrollment |double | Total enrollment of students | |state |character | State name | |category |character | Group/Racial/Gender category | |enrollment |double | enrollment by category | ### A3. Pre-processing Tip: Cool way to quickly summarise your data ``` #install.packages("summarytools") summarytools::dfSummary(diversity_school) %>% view #install.packages("skimr") skimr::skim(diversity_school) ``` ### B. Think of questions we can ask from the data (5 minutes) Talk to the people nearest you and brainstorm some questions we can ask with this dataset. What could this data tell us? What are some interesting questions we could ask? How do you plan to visualise it? #### Question ideas What are the most diverse universities among the top 100 largest universities? **Example**: :::spoiler https://twitter.com/thomas_mock/status/1237098932775215104 ::: :::info **Type in the questions below**: - Q1 Do higher tution costs lead to a higher salary potential? - Q2 Is there a link between income level and diversity? - Approach: - Calculate a diversity index (HHI or Shannon-Wiener) - join `tuition_income.csv` and `diversity_school.csv` - create a scatterplot: diversity against early career pay - Q3 What's the best "value" university? - Highest income per tuition fee - Q4 Is there an association between tuition costs and enrolment numbers? ::: ### C. Start coding! Share your code here! (30 minutes) Share your code and your pretty figures here. Stuck? Share what you have (even code that doesn't work) and ask for help. #### Data Pre-processing ``` ``` #### Q1 Do higher tution costs lead to a higher salary potential? ##### Answer Looks like it ``` cost_salary <- left_join(tuition_cost, salary_potential, by = c("name")) ggplot(cost_salary) + geom_point(aes(in_state_tuition, early_career_pay), colour = "blue") + geom_point(aes(in_state_tuition, mid_career_pay), colour = "red")+ geom_smooth(method = "glm", aes(in_state_tuition, early_career_pay), colour = "blue") + geom_smooth(method = "glm", aes(in_state_tuition, mid_career_pay), colour = "red") ``` ![](https://i.imgur.com/qI9VVPV.png) Tighter trend when we use out_of_state rather than in_state, probably because it filters out cheaper, public universities ``` ggplot(cost_salary) + geom_point(aes(out_of_state_tuition, early_career_pay), colour = "blue") + geom_point(aes(out_of_state_tuition, mid_career_pay), colour = "red")+ geom_smooth(method = "glm", aes(out_of_state_tuition, early_career_pay), colour = "blue") + geom_smooth(method = "glm", aes(out_of_state_tuition, mid_career_pay), colour = "red") ``` ![](https://i.imgur.com/vt3R3DO.png) #### Q2 ##### Answer ``` # Convert diversity_school to long format diversity_long <- diversity_school %>% pivot_wider(names_from = category, values_from = enrollment) %>% select(-c(Women, "Total Minority")) # Calculate diversity index #install.packages("vegan") library(vegan) # Calculate diversity index and join the table with tuition_income diversity_income_lvl<- plyr::ddply(diversity_long,~name,function(x) { data.frame(SHANNON=diversity(x[-c(1,2,3)], index="shannon")) }) %>% left_join(tuition_income, by="name") %>% mutate(income_lvl=as_factor(income_lvl)) # Visualise: scatterplot diversity_income_lvl %>% drop_na() %>% ggplot() + geom_quasirandom(aes(x = SHANNON, y=early_career_pay), alpha=0.2) + geom_quantile(aes(x = SHANNON, y = early_career_pay), quantiles=c(0.01, 0.5, 0.99))+ theme_classic()+ ylab("Early Career Pay (USD/year)")+ xlab("Diversity Index (Shannon)") ``` ![](https://i.imgur.com/oTthhxt.png) ``` #p = proportion of each type Shannon = -(p1*log(p1)+ p2*log(p2)+ etc...) ``` #### Q3 What’s the best “value” university? ##### Answer Based on "out of state fees" or "in state": Brigham Young University-Idaho ``` cost_salary <- cost_salary %>% mutate(value.out = early_career_pay/out_of_state_tuition, value.in = early_career_pay/in_state_tuition) ``` #### Q4 Is there an association between tuition costs and enrolment numbers? ##### Answer First I plotted one against the other ``` ggplot(cost_diversity, aes(in_state_tuition, total_enrollment)) + geom_point() ``` ![](https://i.imgur.com/PdqhR7B.png) It seemed bunched up on the y axis, so I transformed it to a log10 scale. ``` ggplot(cost_diversity, aes(in_state_tuition, total_enrollment)) + geom_point()+ scale_y_log10() ``` ![](https://i.imgur.com/sXFCctg.png) Hmm, there seems to be a trend there. But there's also a big cluster on the left that doesn't seem to be part of that trend. ❓What do you think the cluster is? :::spoiler Answer ``` ggplot(cost_diversity, aes(in_state_tuition, total_enrollment)) + geom_point(aes(colour = type))+ scale_y_log10() ``` ![](https://i.imgur.com/sImiUUg.png) ::: ### D. Wrap up (10 minutes) #### Cool R things I learnt this week :::success :tada: ::: #### Make something cool? Post it on twitter! #TidyTuesday Or see what other people around the world did with the data: https://twitter.com/hashtag/TidyTuesday?src=hashtag_click&f=live #### What could be improved from the next meeting? --- ### E Help! - ask questions about today's Tidy Tuesday here ::: info If you help someone in person, please put it here as well, so others can learn. :+1: ::: #### Q. How do I change the background? A. It depends on what you want to change it to. In ggplot, the best way to change the background is to use `theme()`. #### Q. How can I calculate a diversity index (Shannon-Wiener)? ::: spoiler Answer: There are a number of packages that can help you calculate this (e.g. vegan). ``` library(vegan) diversity(data[-1], index="shannon") Site1 Site2 Site3 Site4 Site5 0.4851 1.2399 1.0905 0.5723 1.2129 Site6 Site7 Site8 Site9 Site10 1.0404 0.9613 0.8522 0.8162 0.6274 #OR library(plyr) ddply(data,~Sites,function(x) { + data.frame(SHANNON=diversity(x[-1], index="shannon")) + }) Sites SHANNON 1 Site1 0.4851 2 Site2 1.2399 3 Site3 1.0905 4 Site4 0.5723 5 Site5 1.2129 6 Site6 1.0404 7 Site7 0.9613 8 Site8 0.8522 9 Site9 0.8162 10 Site10 0.6274 # source: https://www.flutterbys.com.au/stats/tut/tut13.2.html ``` ::: ### F General R help - Stuck on something? Need advice on you current project? Can you help answer someone else's question? (N.B. this document is public, so don't include sensitive or private information)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully