#any packages used put here
library(readxl)
library(Metrics)
hwdata<- read_excel('/Users/dylansnelsire/Desktop/301 Data.xlsx')
hwdata$size <- as.double(hwdata$size)
## Warning: NAs introduced by coercion
hwdata
## # A tibble: 99 × 4
##    School      size average_viewers `average NIL spending`
##    <chr>      <dbl>           <dbl>                  <dbl>
##  1 Alabama    38316         5110000                 217000
##  2 Georgia    40118         3500000                 139000
##  3 Texas      51991         3060000                 291000
##  4 Ohio State 61677         5800000                 125000
##  5 LSU        35912         3220000                  98000
##  6 Miami      19096          608000                 100000
##  7 Oklahoma   28042         1748000                 122000
##  8 Oregon     22257         2210000                  76000
##  9 Notre Dame 13139         3300000                  83000
## 10 Clemson    27341         2590000                  89000
## # … with 89 more rows
#splitting the data
## 75% of the sample size
smp_size <- floor(0.80 * nrow(hwdata))

## set the seed to make your partition reproducible
set.seed(123)
train_ind <- sample(seq_len(nrow(hwdata)), size = smp_size)

train <- hwdata[train_ind, ]
test <- hwdata[-train_ind, ]
#multiple linear regreassion model
names(train)
## [1] "School"               "size"                 "average_viewers"     
## [4] "average NIL spending"
model <- lm(average_viewers ~ size, data = train)
summary(model)
## 
## Call:
## lm(formula = average_viewers ~ size, data = train)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1857488  -566617  -370016   320428  4042506 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 1.817e+05  2.547e+05   0.714 0.477680    
## size        2.555e+01  7.044e+00   3.627 0.000516 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1054000 on 76 degrees of freedom
##   (1 observation deleted due to missingness)
## Multiple R-squared:  0.1476, Adjusted R-squared:  0.1363 
## F-statistic: 13.16 on 1 and 76 DF,  p-value: 0.0005164
#predicting r and rse
print("predict function")
## [1] "predict function"
predict(model, hwdata = size, se.fit=TRUE, interval="confidence")
## $fit
##          fit         lwr       upr
## 1   958144.4  719375.996 1196912.9
## 2   897619.0  653581.899 1141656.2
## 3  1029758.1  791317.737 1268198.4
## 4  2453369.8 1619375.890 3287363.7
## 5   498136.0  135160.742  861111.3
## 6   633417.6  322731.807  944103.4
## 7   832545.9  578079.239 1087012.6
## 8   779787.4  513624.009 1045950.8
## 9   535641.9  187964.730  883319.0
## 10  723426.5  441996.671 1004856.3
## 11  821636.5  564975.560 1078297.5
## 12 1479700.2 1123854.946 1835545.5
## 13  517399.9  162349.007  872450.8
## 14 1014249.9  776289.045 1252210.7
## 15 1217517.1  950821.068 1484213.2
## 16  898155.6  654184.518 1142126.6
## 17  553347.3  212697.998  893996.5
## 18  575779.2  243838.650  907719.8
## 19  983974.4  746072.468 1221876.4
## 20  952140.5  713050.488 1191230.4
## 21  449286.5   65642.370  832930.6
## 22 1091918.6  848556.526 1335280.7
## 23 2034776.2 1417602.941 2651949.5
## 24 1359926.9 1049879.587 1669974.1
## 25  573633.1  240869.226  906397.0
## 26  510348.4  152412.718  868284.1
## 27 1134151.0  884820.912 1383481.1
## 28  927894.5  687051.044 1168738.0
## 29 1521345.0 1148174.466 1894515.5
## 30  579688.2  249241.716  910134.7
## 31 1383304.1 1064867.081 1701741.2
## 32 1007760.5  769910.058 1245610.9
## 33  463696.1   86229.347  841162.8
## 34  865912.8  617380.355 1114445.3
## 35  945855.4  706380.727 1185330.1
## 36  536944.9  189789.359  884100.3
## 37  708684.7  422843.265  994526.2
## 38  805898.4  545861.293 1065935.5
## 39 1099225.6  854977.984 1343473.3
## 40  750355.0  476549.340 1024160.7
## 41  991639.1  753832.073 1229446.1
## 42 1441734.5 1101113.590 1782355.5
## 43 1466261.5 1115871.355 1816651.6
## 44 1178120.7  920497.627 1435743.8
## 45 1313632.2 1019251.731 1608012.7
## 46  734131.5  455801.556 1012461.4
## 47  846112.4  594202.336 1098022.5
## 48 1062230.8  821810.509 1302651.0
## 49 1451698.6 1107139.013 1796258.2
## 50 1332334.0 1031785.057 1632883.0
## 51 1382920.9 1064623.775 1701218.0
## 52  596243.9  272044.067  920443.8
## 53 1003008.4  765204.995 1240811.7
## 54 1039517.8  800620.484 1278415.1
## 55  990106.2  752286.107 1227926.2
## 56  669594.9  371306.656  967883.1
## 57  249340.6 -225364.931  724046.1
## 58  540598.3  194901.774  886294.9
## 60  642232.0  334638.940  949825.0
## 61 1978057.6 1389501.899 2566613.3
## 62 2171488.5 1484432.679 2858544.3
## 63  987168.0  749314.682 1225021.4
## 64 1212075.2  946718.918 1477431.5
## 65 1757493.7 1277226.339 2237761.1
## 66  631884.7  320656.455  943112.9
## 67 1302262.9 1011519.094 1593006.8
## 68 1627960.6 1208011.266 2047910.0
## 69  659477.5  357802.593  961152.4
## 70  486715.7  118979.461  854451.9
## 71  410298.8    9634.755  810962.9
## 72 1334735.6 1033378.322 1636092.9
## 73 1113839.6  867634.227 1360045.0
## 74  944169.2  704582.927 1183755.4
## 75  873475.3  626118.891 1120831.7
## 76  543127.7  198437.916  887817.5
## 77 1510026.8 1141624.755 1878428.8
## 78  709068.0  423343.228  994792.7
## 79 1519863.1 1147319.367 1892406.9
## 
## $se.fit
##  [1] 119883.4 122528.7 119718.6 418740.5 182246.5 155992.4 127765.3 133638.1
##  [9] 174565.4 141303.2 128867.1 178666.6 178267.7 119477.9 133905.6 122495.6
## [17] 171036.8 166664.2 119448.3 120044.8 192624.1 122189.8 309876.9 155671.8
## [25] 167077.6 179716.1 125186.3 120925.2 187365.4 165914.1 159884.2 119422.4
## [33] 189522.5 124785.8 120238.0 174303.5 143518.3 130562.2 122634.4 137475.3
## [41] 119400.7 171022.6 175927.6 129350.1 147805.7 139746.8 126481.7 120712.7
## [49] 173000.1 150902.8 159814.0 162777.7 119398.8 119948.1 119407.2 149767.7
## [57] 238345.2 173571.0 154439.6 295508.2 344964.2 119423.9 133232.9 241137.7
## [65] 156264.7 145979.7 210852.6 151468.1 184636.9 201169.6 151308.7 123617.4
## [73] 120294.0 124195.3 173065.5 184971.2 143459.7 187050.7
## 
## $df
## [1] 76
## 
## $residual.scale
## [1] 1054419