Question 1

data(cars)

head(cars)
##   speed dist
## 1     4    2
## 2     4   10
## 3     7    4
## 4     7   22
## 5     8   16
## 6     9   10
median(cars[,1])
## [1] 15

The median of the first column (speed) is 15.

Question 2

url_btc <- "https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=100"

btc_data <- fromJSON(url_btc)

btc_prices <- btc_data$Data$Data

head(btc_prices)
##         time     high      low     open volumefrom   volumeto    close
## 1 1763942400 89227.26 85242.01 86823.45   44709.41 3899541726 88288.33
## 2 1764028800 88494.81 86089.70 88288.33   32065.82 2799155557 87340.82
## 3 1764115200 90634.17 86298.47 87340.82   30484.49 2694221351 90487.28
## 4 1764201600 91934.77 90083.46 90487.28   21381.51 1949917850 91327.26
## 5 1764288000 93116.85 90242.43 91327.26   28364.69 2595318230 90917.53
## 6 1764374400 91201.70 90211.19 90917.53    9605.76  871610719 90842.76
##   conversionType conversionSymbol
## 1         direct                 
## 2         direct                 
## 3         direct                 
## 4         direct                 
## 5         direct                 
## 6         direct
max(btc_prices$close)
## [1] 96945.09

The maximum daily closing price of BTC in the last 100 days is shown above.

Question 3

Research Questions

  1. Do higher tuition universities have higher graduation outcomes?
  2. Do private and public universities differ in tuition and outcomes?
  3. What is the relationship between tuition and graduation rate?

Data Source

U.S. College Scorecard
https://collegescorecard.ed.gov/

Load Data

college <- read.csv("https://raw.githubusercontent.com/selva86/datasets/master/College.csv")

head(college)
##   Private Apps Accept Enroll Top10perc Top25perc F.Undergrad P.Undergrad
## 1     Yes 1660   1232    721        23        52        2885         537
## 2     Yes 2186   1924    512        16        29        2683        1227
## 3     Yes 1428   1097    336        22        50        1036          99
## 4     Yes  417    349    137        60        89         510          63
## 5     Yes  193    146     55        16        44         249         869
## 6     Yes  587    479    158        38        62         678          41
##   Outstate Room.Board Books Personal PhD Terminal S.F.Ratio perc.alumni Expend
## 1     7440       3300   450     2200  70       78      18.1          12   7041
## 2    12280       6450   750     1500  29       30      12.2          16  10527
## 3    11250       3750   400     1165  53       66      12.9          30   8735
## 4    12960       5450   450      875  92       97       7.7          37  19016
## 5     7560       4120   800     1500  76       72      11.9           2  10922
## 6    13500       3335   500      675  67       73       9.4          11   9727
##   Grad.Rate
## 1        60
## 2        56
## 3        54
## 4        59
## 5        15
## 6        55

Data Preparation

college_clean <- college %>%
select(Private, Outstate, Grad.Rate, Top10perc, Room.Board) %>%
rename(
institution_type = Private,
tuition = Outstate,
grad_rate = Grad.Rate,
top10_percent = Top10perc,
room_board = Room.Board
) %>%
filter(!is.na(tuition), !is.na(grad_rate)) %>%
mutate(
institution_type = ifelse(institution_type == "Yes", "Private", "Public")
)

head(college_clean, 10)
##    institution_type tuition grad_rate top10_percent room_board
## 1           Private    7440        60            23       3300
## 2           Private   12280        56            16       6450
## 3           Private   11250        54            22       3750
## 4           Private   12960        59            60       5450
## 5           Private    7560        15            16       4120
## 6           Private   13500        55            38       3335
## 7           Private   13290        63            17       5720
## 8           Private   13868        73            37       4826
## 9           Private   15595        80            30       4400
## 10          Private   10468        52            21       3380
summary(college_clean)
##  institution_type      tuition        grad_rate      top10_percent  
##  Length:777         Min.   : 2340   Min.   : 10.00   Min.   : 1.00  
##  Class :character   1st Qu.: 7320   1st Qu.: 53.00   1st Qu.:15.00  
##  Mode  :character   Median : 9990   Median : 65.00   Median :23.00  
##                     Mean   :10441   Mean   : 65.46   Mean   :27.56  
##                     3rd Qu.:12925   3rd Qu.: 78.00   3rd Qu.:35.00  
##                     Max.   :21700   Max.   :118.00   Max.   :96.00  
##    room_board  
##  Min.   :1780  
##  1st Qu.:3597  
##  Median :4200  
##  Mean   :4358  
##  3rd Qu.:5050  
##  Max.   :8124

Correlation Between Tuition and Graduation Rate

cor(college_clean$tuition, college_clean$grad_rate)
## [1] 0.5712899

Answer: Higher tuition universities tend to have slightly higher graduation rates, showing a positive relationship between tuition and outcomes.

Average Tuition and Graduation Rate by Institution Type

college_clean %>%
group_by(institution_type) %>%
summarise(
n = n(),
average_tuition = mean(tuition),
average_grad_rate = mean(grad_rate)
)
## # A tibble: 2 × 4
##   institution_type     n average_tuition average_grad_rate
##   <chr>            <int>           <dbl>             <dbl>
## 1 Private            565          11802.              69.0
## 2 Public             212           6813.              56.0

Answer: Private universities generally have higher tuition and slightly higher graduation rates compared to public universities.

Tuition vs Graduation Rate Visualization

ggplot(college_clean, aes(x = tuition, y = grad_rate)) +
geom_point(alpha = 0.5) +
geom_smooth(method = "lm") +
labs(
title = "Tuition vs Graduation Rate",
x = "Out-of-State Tuition",
y = "Graduation Rate"
)

Answer: The visualization shows a positive trend, meaning schools with higher tuition often have higher graduation rates.

Data Preview

head(college_clean, 20)
##    institution_type tuition grad_rate top10_percent room_board
## 1           Private    7440        60            23       3300
## 2           Private   12280        56            16       6450
## 3           Private   11250        54            22       3750
## 4           Private   12960        59            60       5450
## 5           Private    7560        15            16       4120
## 6           Private   13500        55            38       3335
## 7           Private   13290        63            17       5720
## 8           Private   13868        73            37       4826
## 9           Private   15595        80            30       4400
## 10          Private   10468        52            21       3380
## 11          Private   16548        73            37       5406
## 12          Private   17080        76            44       4440
## 13          Private    9690        74            38       4785
## 14          Private   12572        68            44       4552
## 15          Private    8352        55            23       3640
## 16          Private    8700        69             9       4780
## 17          Private   19760       100            83       5300
## 18          Private   10100        59            19       3520
## 19          Private    9996        46            14       3090
## 20           Public    5130        34            24       3592