library(SciViews)
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
#--Run a correlation Analysis and interpret it
#1-- then fit a linear model with expenditures and RVUs
#2 --- interpret the results and regression assumptions
#3--- then fit the linear model of ln(Expenditures)~RVUs
#4-- How did this transformation affect the assumption
Edata <- read.csv("C:/Users/polhe/Downloads/week 6 data.csv")
attach(Edata)
names(Edata)
## [1] "Expenditures" "Enrolled" "RVUs" "FTEs"
## [5] "Quality.Score"
print(Edata)
## Expenditures Enrolled RVUs FTEs Quality.Score
## 1 114948144 25294 402703.73 954.91 0.67
## 2 116423140 42186 638251.99 949.25 0.58
## 3 119977702 23772 447029.54 952.51 0.52
## 4 19056531 2085 43337.26 199.98 0.93
## 5 246166031 67258 1579789.36 2162.15 0.96
## 6 152125186 23752 673036.55 1359.07 0.56
## 7 737556867 53781 2397334.12 5798.04 0.84
## 8 431714041 98763 2256730.04 3623.94 0.82
## 9 378230874 47986 1558835.73 3305.32 0.76
## 10 289246447 64634 1713157.92 2404.80 0.81
## 11 292001890 76714 1156318.42 1690.42 0.83
## 12 33290437 11163 161196.70 214.72 0.70
## 13 89918238 33266 550546.15 786.15 0.60
## 14 200289585 35008 1050922.34 1784.82 0.75
## 15 154264931 42984 1010128.12 1325.65 0.64
## 16 111397716 15821 372044.89 957.25 0.73
## 17 63691831 21657 485389.31 483.36 0.68
## 18 177511820 57006 838595.08 1323.09 0.83
## 19 155047333 18580 1030776.45 1326.46 0.83
## 20 421917863 40639 1357463.45 3495.57 0.82
## 21 49422291 17343 248057.53 337.61 0.76
## 22 704000406 108960 3017131.83 5345.62 0.85
## 23 231372781 48338 1665055.71 2032.83 0.75
## 24 92965171 27454 560475.02 762.67 0.89
## 25 148661984 20476 736191.93 1166.26 0.84
## 26 52500954 17125 254384.25 428.16 0.84
## 27 48990120 13781 240808.17 434.20 0.59
## 28 175601378 30571 994000.52 1474.55 0.93
## 29 627739846 65154 2707224.50 4784.79 0.88
## 30 56291987 12107 184173.46 500.96 0.74
## 31 384804579 65885 1648839.75 3444.47 0.70
## 32 211543524 57098 1102229.23 1744.00 0.90
## 33 481316889 115521 2552169.39 4003.16 0.73
## 34 123018246 30540 488432.15 753.12 0.84
## 35 17193213 4327 49293.75 177.65 0.56
## 36 30664899 13527 128738.76 283.17 0.75
## 37 19768937 7209 89148.62 206.42 0.69
## 38 55784977 17266 174289.61 586.06 0.71
## 39 37992105 14842 146174.89 348.40 0.71
## 40 39448397 11953 138345.36 373.62 0.70
## 41 49637051 25420 241419.44 497.49 0.74
## 42 28530205 12110 124162.92 260.72 0.55
## 43 30673348 11466 113732.83 298.50 0.76
## 44 25234710 11454 113222.94 265.81 0.53
## 45 49671099 16845 145258.22 413.01 0.40
## 46 22557139 8131 91710.45 217.08 0.65
## 47 15516577 4521 54406.39 204.56 0.71
## 48 47429842 8002 120720.78 426.67 0.76
## 49 43366439 13364 146786.49 406.80 0.74
## 50 20223890 10009 83916.19 202.41 0.62
## 51 18363510 6103 60862.37 188.40 0.75
## 52 47778415 22259 218827.23 410.02 0.63
## 53 45322490 22959 232476.04 366.63 0.80
## 54 41314090 7604 111419.60 464.88 0.73
## 55 41831991 10417 142963.42 378.73 0.81
## 56 20109657 6149 72473.83 229.39 0.65
## 57 50755308 7042 127018.26 517.54 0.91
## 58 69272642 24565 323225.69 703.60 0.67
## 59 40575888 14849 129274.86 343.20 0.41
## 60 20958223 2578 49777.27 207.06 0.68
## 61 25628795 7691 93237.75 277.07 0.53
## 62 44432989 16932 185326.68 329.76 0.59
## 63 33521880 12213 132282.28 352.28 0.69
## 64 46306286 14439 143826.20 307.96 0.76
## 65 15736197 3887 45836.14 169.74 0.72
## 66 91103765 22214 356917.60 947.74 0.65
## 67 29637497 11648 133160.97 288.03 0.64
## 68 32821893 11552 131678.51 332.10 0.56
## 69 28426761 11298 110997.40 288.20 0.76
## 70 37534503 7319 109734.18 457.09 0.62
## 71 35432093 11743 120563.35 352.10 0.65
## 72 82601055 28151 320705.78 746.06 0.85
## 73 64545467 27250 313899.05 546.20 0.66
## 74 28901543 6758 71855.26 268.14 0.67
## 75 671959058 54771 1865586.33 5697.77 0.81
## 76 29361928 12577 118062.13 300.97 0.89
## 77 320604335 40225 808455.56 2415.15 0.59
## 78 19790938 8265 75995.61 161.15 0.68
## 79 28382056 12188 125125.92 268.02 0.50
## 80 133789826 35570 550683.00 1239.03 0.77
## 81 11906768 1424 23581.51 137.55 0.72
## 82 19448328 6766 48223.16 170.92 0.61
## 83 150947798 37795 608182.20 1260.65 0.63
## 84 113604093 33319 406929.00 640.55 0.79
## 85 15487046 4227 44759.38 168.01 0.67
## 86 55312465 22109 256084.38 502.99 0.60
## 87 49645517 17442 242765.52 433.78 0.78
## 88 151611402 27667 556371.89 1373.80 0.63
## 89 47833729 15449 181309.06 429.29 0.76
## 90 31467898 10324 112718.98 311.40 0.68
## 91 221899340 27207 710440.86 1824.36 0.68
## 92 51656073 10054 199461.51 492.75 0.72
## 93 93746534 20601 231366.13 919.47 0.78
## 94 45093715 16176 185456.99 421.68 0.70
## 95 290852934 36549 855724.09 2271.85 0.83
## 96 16275452 2062 32058.03 185.23 0.49
## 97 23880752 8922 101135.34 228.50 0.72
## 98 30422168 10949 108488.17 300.02 0.41
## 99 179510966 33125 684679.01 1587.88 0.81
## 100 15868393 4943 55961.81 151.10 0.71
## 101 191489002 45613 738618.70 1649.62 0.55
## 102 33946305 9001 90746.40 389.07 0.82
## 103 112886022 26776 503561.98 966.04 0.81
## 104 118474189 10184 584607.15 1129.51 0.78
## 105 170396460 34609 714332.05 1315.37 0.83
## 106 242465456 31301 1212558.88 2432.32 0.79
## 107 279086160 48049 1468797.93 2317.23 0.83
## 108 90695660 10976 280721.41 811.31 0.73
## 109 33692909 1218 52387.28 290.49 0.73
## 110 281085750 56812 1387650.41 2353.20 0.81
## 111 70232710 14086 297280.10 659.61 0.72
## 112 67058602 5628 154626.03 556.60 0.78
## 113 57406032 14897 327289.34 473.52 0.69
## 114 133421055 15611 734445.95 1318.31 0.78
## 115 239806816 46403 1030474.35 2031.98 0.78
## 116 44222933 2642 90139.68 398.66 0.82
## 117 55797686 7852 167676.80 503.27 0.64
## 118 74134323 14783 337025.73 636.82 0.64
## 119 129861050 21585 480628.61 1306.36 0.58
## 120 38680530 13153 243534.20 332.89 0.76
## 121 49129643 16577 231843.71 419.97 0.91
## 122 49575746 14431 279027.99 401.68 0.79
## 123 66972157 12728 169068.75 471.70 0.73
## 124 75793328 29339 525417.05 664.01 0.86
## 125 38437460 15428 177338.98 321.46 0.86
## 126 59443879 21742 347643.62 551.92 0.71
## 127 806367625 101454 3434703.16 6658.61 0.92
## 128 785079539 40402 1844285.41 4655.55 0.92
## 129 129946379 25540 460637.39 910.46 0.72
## 130 117827082 42206 763481.71 974.07 0.53
## 131 124633496 24435 471401.75 941.42 0.60
## 132 15335594 1906 45977.13 186.63 0.70
## 133 280918530 71993 1810996.19 2094.17 0.93
## 134 142671518 29449 680826.00 1227.45 0.67
## 135 1052311021 57397 2892975.46 7518.63 0.79
## 136 452667260 100569 2390290.31 3587.36 0.76
## 137 370586067 45085 1624727.69 3107.84 0.76
## 138 294389493 68214 1836855.21 2311.60 0.85
## 139 478981007 81497 1736067.57 3542.01 0.69
## 140 34827530 10631 150177.82 208.10 0.64
## 141 94258566 34222 568984.13 788.41 0.49
## 142 204873437 32113 945113.43 1598.94 0.73
## 143 164690465 45838 1157782.51 1363.49 0.65
## 144 105635716 13241 338120.18 811.58 0.63
## 145 73110154 21077 512124.61 501.03 0.73
## 146 178424383 59407 989358.63 1164.10 0.84
## 147 168267964 20236 1071997.55 1297.82 0.85
## 148 453595967 41256 1453868.97 3361.97 0.73
## 149 55868770 17757 264847.07 338.83 0.83
## 150 672113787 116389 3093666.05 5004.26 0.79
## 151 263617995 54261 1692788.53 2050.02 0.74
## 152 88213119 25920 587833.28 725.47 0.91
## 153 154460753 21819 723014.94 1105.41 0.79
## 154 54996100 16242 261201.56 395.37 0.86
## 155 48828341 12078 252941.14 394.23 0.94
## 156 187119684 30279 1015301.82 1422.28 0.82
## 157 674563921 66212 2673082.99 4685.47 0.74
## 158 59942400 11141 213605.00 483.70 0.83
## 159 417756027 72259 1852559.13 3478.57 0.81
## 160 214429435 58625 1290205.03 1671.86 0.85
## 161 522108466 116298 2616782.68 3879.58 0.79
## 162 122543052 29016 479062.73 720.95 0.77
## 163 18386529 4199 56064.49 156.28 0.59
## 164 33333082 13781 133997.55 270.14 0.83
## 165 20523439 7050 91612.91 176.79 0.76
## 166 59426076 17134 172765.34 532.25 0.57
## 167 40355791 13909 153028.08 351.94 0.78
## 168 41684323 12776 147494.34 373.30 0.67
## 169 53590324 23901 247909.39 463.56 0.78
## 170 29439049 11834 134265.66 249.42 0.71
## 171 30939512 10869 121982.43 297.32 0.82
## 172 26985594 11279 122499.26 256.12 0.64
## 173 51174054 16994 185507.03 394.24 0.39
## 174 23753605 7853 94789.14 210.53 0.59
## 175 15659058 4749 63977.31 187.68 0.72
## 176 50888100 7850 136429.27 412.04 0.85
## 177 43768308 12351 154733.89 350.68 0.81
## 178 23082323 9982 90140.88 241.51 0.66
## 179 18261275 5937 67479.03 186.47 0.66
## 180 49348318 19519 227044.07 394.49 0.68
## 181 43254472 24654 258675.34 330.13 0.85
## 182 43335191 7259 128745.31 398.97 0.70
## 183 42773074 10141 165737.75 374.74 0.67
## 184 21323162 6142 62422.39 193.86 0.49
## 185 56032849 6812 143776.97 459.01 0.63
## 186 70268334 24571 344199.65 657.36 0.69
## 187 42586104 12020 139945.55 320.77 0.31
## 188 21902259 2662 55472.38 190.79 0.74
## 189 27534164 7644 99528.47 271.41 0.68
## 190 47356861 16513 192851.20 307.29 0.60
## 191 33675604 11456 146346.45 316.67 0.64
## 192 49966638 14648 168293.14 277.44 0.78
## 193 15484896 3810 47317.01 150.47 0.70
## 194 95034213 17811 359659.92 811.18 0.59
## 195 30276033 11075 129988.91 281.42 0.76
## 196 33343818 11080 136237.85 324.82 0.48
## 197 28896477 11666 112823.36 265.84 0.79
## 198 40787554 7357 115452.21 427.65 0.85
## 199 38388629 8548 109251.92 330.95 0.61
## 200 80916337 27326 361224.99 685.37 0.74
## 201 68113499 26144 330031.76 518.75 0.66
## 202 29372038 7087 64318.29 267.16 0.73
## 203 651743770 50687 1601793.92 5048.47 0.88
## 204 29696092 12393 127030.34 276.22 0.80
## 205 348797885 39078 863863.99 2340.06 0.58
## 206 20663099 8438 82060.19 164.62 0.58
## 207 30201767 11945 144498.15 272.21 0.54
## 208 150320044 37600 620445.23 1284.54 0.76
## 209 12085971 1445 23218.01 120.30 0.79
## 210 20375822 6716 58518.34 165.32 0.68
## 211 160608494 37162 641388.93 1228.19 0.58
## 212 96365310 33829 415452.70 581.08 0.68
## 213 14780257 4145 53073.19 145.87 0.67
## 214 57948488 20244 262939.04 454.48 0.54
## 215 50683600 17047 256896.61 396.00 0.72
## 216 148969823 28338 558736.60 1130.04 0.63
## 217 49950740 13792 189081.27 420.35 0.80
## 218 32146051 10634 99266.92 288.41 0.83
## 219 235165404 26731 740702.89 1684.47 0.76
## 220 49943851 9517 195731.34 444.26 0.70
## 221 93550306 20120 235349.05 839.14 0.65
## 222 46805669 16892 213023.68 408.52 0.61
## 223 322738262 37171 903695.93 2031.06 0.87
## 224 17519828 2423 34588.14 184.65 0.60
## 225 25110314 8647 92861.20 213.82 0.57
## 226 32623104 10319 118254.98 293.35 0.48
## 227 191736477 34861 721944.14 1549.64 0.84
## 228 16646964 5166 60638.99 146.90 0.66
## 229 223513993 47105 869628.09 1659.27 0.58
## 230 35964730 8748 97346.03 361.02 0.83
## 231 121800528 26994 519196.24 965.89 0.70
## 232 121524734 10564 564985.07 1078.21 0.84
## 233 182373869 34255 747807.29 1319.79 0.79
## 234 256575567 31548 1331724.66 2282.88 0.76
## 235 288406519 48251 1483892.38 2229.13 0.76
## 236 95104995 10983 301374.21 806.66 0.67
## 237 36287531 1602 49394.58 280.38 0.61
## 238 287374111 56569 1358605.37 2252.70 0.71
## 239 73206957 13163 303746.49 615.57 0.77
## 240 63328607 5319 153975.67 531.35 0.81
## 241 59419192 14653 332710.38 427.31 0.77
## 242 144359005 16182 783710.24 1265.67 0.67
## 243 246761080 45429 1075503.19 1973.93 0.87
## 244 49838003 2700 99966.78 404.84 0.87
## 245 59641487 8344 186116.14 494.66 0.66
## 246 78802547 14439 353629.69 643.62 0.66
## 247 141710583 20243 525514.30 1281.47 0.80
## 248 44037424 13693 244664.82 316.48 0.67
## 249 50511046 16514 213393.96 349.72 0.87
## 250 49336614 14441 294497.96 401.89 0.79
## 251 61325036 12573 191410.10 462.72 0.69
## 252 84252197 29155 520728.07 642.60 0.83
## 253 43864242 15582 178586.90 312.64 0.74
## 254 61412502 21966 349811.35 548.66 0.68
## 255 818656771 100584 3574006.15 6613.28 0.89
## 256 1301993928 50927 2822798.99 7264.44 0.80
## 257 94047315 25065 490004.41 877.76 0.68
## 258 78707019 37484 685670.00 882.74 0.61
## 259 99843160 23433 464193.99 930.94 0.57
## 260 10411614 2146 52575.69 168.81 0.55
## 261 210852507 69862 1497851.52 2074.33 0.93
## 262 107067124 31989 670977.65 1365.40 0.87
## 263 782762374 57259 2694416.86 7410.52 0.82
## 264 337731158 101429 2209837.83 3334.43 0.78
## 265 282567119 44940 1330621.99 3016.47 0.71
## 266 229521482 70900 1782559.31 2330.10 0.83
## 267 380317663 82717 1649419.95 3447.24 0.64
## 268 26083915 11517 146801.47 191.09 0.76
## 269 69635722 32476 531543.72 779.58 0.42
## 270 150516975 32330 838022.94 1538.72 0.66
## 271 123626592 42568 955567.97 1324.11 0.67
## 272 76813305 13182 245494.03 714.26 0.60
## 273 46084228 21118 432508.24 482.78 0.71
## 274 140235269 61512 840078.05 1169.56 0.77
## 275 122357396 22131 992598.16 1285.99 0.78
## 276 360490554 52361 1519461.14 3440.47 0.67
## 277 37884197 17669 254492.22 318.90 0.78
## 278 524079263 119076 2860646.31 4868.98 0.74
## 279 186727705 55480 1469704.84 1985.09 0.57
## 280 63568011 25112 494032.79 670.45 0.90
## 281 110928482 23827 699243.04 1034.51 0.77
## 282 39233373 16640 260642.92 397.81 0.87
## 283 35323954 12072 228236.18 345.64 0.91
## 284 133895187 30483 931018.64 1341.27 0.78
## 285 529484041 67509 2382358.81 4505.88 0.72
## 286 43736668 10878 180151.59 499.05 0.65
## 287 328821735 70252 1773661.16 3362.13 0.78
## 288 160042102 59168 1061118.57 1671.68 0.78
## 289 389431356 119850 2296382.01 3842.06 0.78
## 290 88037818 28051 448635.12 683.56 0.68
## 291 12643654 4176 62945.84 138.28 0.64
## 292 24252878 13885 128449.03 247.60 0.89
## 293 13805046 7456 88515.40 161.19 0.81
## 294 42703747 16813 157896.70 484.02 0.63
## 295 29590277 14476 138303.63 322.78 0.75
## 296 29827614 12618 163418.40 359.91 0.78
## 297 41077626 24956 250186.86 480.69 0.77
## 298 20069865 11401 122452.70 254.62 0.73
## 299 21702658 10566 104959.54 271.87 0.77
## 300 19829246 11045 110138.68 246.52 0.79
## 301 35631699 17212 174017.19 383.20 0.45
## 302 17309855 7802 88910.56 193.31 0.62
## 303 12232590 5041 58002.30 171.03 0.75
## 304 38724750 7633 126546.43 444.72 0.78
## 305 28129131 12915 134342.38 296.44 0.89
## 306 16982095 9906 96588.69 211.67 0.61
## 307 13481673 5633 55652.31 163.42 0.55
## 308 40115495 20690 219136.01 369.63 0.69
## 309 28374756 24649 230505.80 328.96 0.89
## 310 35739680 7267 114423.35 406.87 0.59
## 311 30151930 10063 145334.13 385.38 0.68
## 312 16189811 5999 67858.67 202.65 0.44
## 313 43005541 7012 129690.83 430.12 0.59
## 314 54299717 24207 315507.42 630.25 0.70
## 315 29156276 11793 133477.57 305.89 0.31
## 316 18592043 2500 44197.16 185.50 0.82
## 317 20081127 7446 88526.54 248.49 0.69
## 318 32138620 16419 170237.89 306.84 0.58
## 319 22877488 11449 127905.57 301.17 0.68
## 320 33859690 14823 144092.99 265.25 0.91
## 321 10180284 3685 52157.86 125.00 0.75
## 322 70781594 17746 320445.13 814.42 0.66
## 323 20969209 10753 109821.43 272.34 0.70
## 324 23225910 10673 117906.07 288.43 0.50
## 325 19876545 11915 106202.23 246.63 0.77
## 326 29423436 7619 107960.68 398.87 0.75
## 327 27852806 7943 87815.68 315.10 0.66
## 328 58803092 27118 331616.59 648.77 0.69
## 329 48609297 25552 310370.02 497.67 0.58
## 330 21187801 7384 74864.60 242.31 0.74
## 331 463611180 52490 1426871.64 4665.43 0.88
## 332 20926931 12575 128328.62 261.39 0.75
## 333 248413335 39215 810171.13 2261.38 0.48
## 334 16339169 8284 65142.62 170.92 0.60
## 335 22953113 12253 134131.67 269.36 0.64
## 336 111205662 38545 598097.42 1297.28 0.65
## 337 7839563 1390 23391.25 116.29 0.86
## 338 16286538 6901 47320.66 135.83 0.58
## 339 119293449 37124 623674.43 1186.71 0.63
## 340 68360435 36696 385697.33 578.16 0.59
## 341 10836186 4120 47847.89 135.89 0.71
## 342 40189939 20393 243788.74 441.88 0.55
## 343 35401236 17116 223210.61 343.91 0.72
## 344 107506235 28789 479689.96 1146.34 0.70
## 345 34917728 15227 159420.23 406.61 0.75
## 346 22436001 9892 98620.22 264.85 0.75
## 347 164036058 26372 666386.35 1580.19 0.71
## 348 33399114 9693 176535.27 382.26 0.71
## 349 70201713 19743 197356.55 799.58 0.65
## 350 32754540 17299 207190.31 384.97 0.50
## 351 206886756 37266 783489.55 1870.42 0.81
## 352 13779195 2232 28972.31 162.39 0.55
## 353 17940731 8509 86070.80 205.99 0.44
## 354 21996524 10731 111598.06 279.85 0.40
## 355 145052995 36714 651147.15 1554.25 0.75
## 356 11599674 5117 53306.14 139.95 0.70
## 357 157480675 48077 774026.56 1467.97 0.57
## 358 25699503 9269 94087.39 338.05 0.78
## 359 87606611 26811 460717.48 931.23 0.77
## 360 88268292 10638 584343.14 1032.31 0.85
## 361 137687522 34157 659398.59 1331.56 0.77
## 362 209778567 28452 1207717.46 2291.80 0.77
## 363 217234362 54088 1468947.94 2256.08 0.73
## 364 72748524 12578 272805.82 807.40 0.67
## 365 27017111 2495 45743.93 273.63 0.65
## 366 211706640 55780 1186891.23 2197.67 0.65
## 367 53091253 12886 283437.31 602.52 0.73
## 368 50101230 5085 137424.07 548.62 0.72
## 369 44076052 14108 294641.54 457.95 0.75
## 370 114704162 17808 758965.24 1361.03 0.64
## 371 180743712 47608 997600.45 1919.63 0.89
## 372 41248792 2627 86193.90 436.02 0.91
## 373 43070966 7366 171945.87 492.47 0.74
## 374 57893841 14046 333834.43 632.80 0.68
## 375 115901469 20703 482809.71 1259.61 0.74
## 376 30655008 12915 225910.92 301.84 0.79
## 377 33484177 16302 181430.97 372.68 0.88
## 378 36840773 14143 311830.18 414.35 0.73
## 379 44320061 12909 165571.09 448.58 0.73
## 380 62746031 29229 468078.61 652.88 0.75
## 381 27700261 15128 159782.94 295.72 0.68
## 382 42906055 20627 286767.83 523.77 0.53
## 383 613026612 102325 3313522.61 6392.68 0.82
## 384 973911640 50913 2384670.02 6666.90 0.71
summary(Edata)
## Expenditures Enrolled RVUs FTEs
## Min. :7.840e+06 Min. : 1218 Min. : 23218 Min. : 116.3
## 1st Qu.:3.067e+07 1st Qu.: 10527 1st Qu.: 126191 1st Qu.: 300.7
## Median :5.280e+07 Median : 16466 Median : 246702 Median : 483.1
## Mean :1.248e+08 Mean : 24714 Mean : 546858 Mean :1060.9
## 3rd Qu.:1.445e+08 3rd Qu.: 32020 3rd Qu.: 689063 3rd Qu.:1297.4
## Max. :1.302e+09 Max. :119850 Max. :3574006 Max. :7518.6
## Quality.Score
## Min. :0.3100
## 1st Qu.:0.6500
## Median :0.7300
## Mean :0.7147
## 3rd Qu.:0.7900
## Max. :0.9600
plot(Edata$Expenditures ~ Edata$RVUs, main="Scatterplot")

plot(Expenditures ~ RVUs, data = Edata)

cor(Edata$Expenditures, Edata$RVUs)
## [1] 0.9217239
#There is a positive and nearly linear relationship between Expenditures and RVUs
mod <- lm(Edata$Expenditures~Edata$RVUs)
summary(mod)
##
## Call:
## lm(formula = Edata$Expenditures ~ Edata$RVUs)
##
## Residuals:
## Min 1Q Median 3Q Max
## -185723026 -14097620 2813431 11919781 642218316
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -3.785e+06 4.413e+06 -0.858 0.392
## Edata$RVUs 2.351e+02 5.061e+00 46.449 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 67350000 on 382 degrees of freedom
## Multiple R-squared: 0.8496, Adjusted R-squared: 0.8492
## F-statistic: 2157 on 1 and 382 DF, p-value: < 2.2e-16
attributes(mod)
## $names
## [1] "coefficients" "residuals" "effects" "rank"
## [5] "fitted.values" "assign" "qr" "df.residual"
## [9] "xlevels" "call" "terms" "model"
##
## $class
## [1] "lm"
mod$coef
## (Intercept) Edata$RVUs
## -3785072.1584 235.0719
coef(mod)
## (Intercept) Edata$RVUs
## -3785072.1584 235.0719
#add regression line
plot(Edata$Expenditures, Edata$RVUs, main="Scatterplot")
abline(mod)
abline(mod,col=2,lwd=3)

#Interpretation of the Regression
#confidence intervals
confint(mod)
## 2.5 % 97.5 %
## (Intercept) -1.246170e+07 4891553.9420
## Edata$RVUs 2.251212e+02 245.0226
confint(mod,level=0.99)
## 0.5 % 99.5 %
## (Intercept) -1.520903e+07 7638883.7187
## Edata$RVUs 2.219704e+02 248.1734
anova(mod)
## Analysis of Variance Table
##
## Response: Edata$Expenditures
## Df Sum Sq Mean Sq F value Pr(>F)
## Edata$RVUs 1 9.7876e+18 9.7876e+18 2157.5 < 2.2e-16 ***
## Residuals 382 1.7330e+18 4.5366e+15
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Interpret the results and assumptions. This says that the "Expenditures are -3785072.2 + 235.1" The Y-intercept is -3785072.2 and the slope is 235.1
#--then save the results as a var, mod.
mod <- lm(Edata$Expenditures~Edata$RVUs)
mod$residuals
## 1 2 3 4 5
## 24068890.49 -29826887.48 18678697.21 12654231.60 -121412962.58
## 6 7 8 9 10
## -2301713.52 177796085.09 -94994675.06 15577490.36 -109683745.59
## 11 12 13 14 15
## 23969009.42 -817302.83 -35714612.07 -42967640.21 -79402719.65
## 16 17 18 19 20
## 27725494.25 -46624477.38 -15833235.52 -83474160.14 106601441.33
## 21 22 23 24 25
## -5103987.94 -1457393.33 -156249933.54 -35001677.57 -20610970.15
## 26 27 28 29 30
## -3512558.99 -3832038.55 -54275127.79 -4867452.59 16783056.33
## 31 32 33 34 35
## 993779.97 -43774508.24 -114841312.65 11986651.37 9390710.43
## 36 37 38 39 40
## 4187107.53 2597674.98 18599462.15 7415570.40 10712364.81
## 41 42 43 44 45
## -3328799.74 3128065.03 7723029.70 2404251.61 19310046.94
## 46 47 48 49 50
## 4783662.58 6512236.89 22836852.33 12646134.44 4282625.10
## 51 52 53 54 55
## 7841549.74 123357.55 -5541019.40 18907546.89 12010382.12
## 56 57 58 59 60
## 6858169.69 24681958.34 -2923558.41 13972075.36 13042058.66
## 61 62 63 64 65
## 7496293.13 4652968.87 6211107.02 16281862.07 8746481.26
## 66 67 68 69 70
## 10987543.10 2120168.67 5653049.16 6119465.33 15524154.73
## 71 72 73 74 75
## 10876110.73 10997214.66 -5458302.70 15795463.25 237197231.39
## 76 77 78 79 80
## 5393912.59 134344233.11 5711578.34 2753541.79 8124806.01
## 81 82 83 84 85
## 10148490.07 11897490.87 11766332.69 21731597.80 8750445.85
## 86 87 88 89 90
## -1100700.75 -3636759.80 24609084.61 8998138.14 8755906.93
## 91 92 93 94 95
## 58679739.26 8553351.69 43143933.56 5283062.77 93481329.49
## 96 97 98 99 100
## 12524582.52 3891748.74 8704721.69 22347251.44 6498416.50
## 101 102 103 104 105
## 21645582.35 16399450.19 -1702170.52 -15165444.23 6262149.18
## 106 107 108 109 110
## -38787975.11 -62401868.03 28491020.77 25163204.47 -41326777.50
## 111 112 113 114 115
## 4135587.83 34495441.23 -15745418.08 -35441467.94 1356338.88
## 116 117 118 119 120
## 26818700.97 20166656.04 -1305879.22 20663848.44 -14782441.65
## 121 122 123 124 125
## -1585223.51 -12230817.98 31013919.46 -43932376.68 535123.66
## 126 127 128 129 130
## -18492290.00 2750545.32 355324960.04 25448550.64 -57860931.82
## 131 132 133 134 135
## 17605269.52 8312735.40 -141010688.51 -13586462.03 376038893.80
## 136 137 138 139 140
## -105437720.51 -7556664.19 -133618454.62 74665400.46 3310019.02
## 141 142 143 144 145
## -35708534.69 -13511088.31 -103686581.88 29938239.24 -43490872.19
## 146 147 148 149 150
## -50360944.65 -79943450.18 115617317.67 -2604258.22 -51335055.92
## 151 152 153 154 155
## -130523926.66 -46184886.67 -11714660.95 -2619971.00 -6845937.39
## 156 157 158 159 160
## -47764157.87 49982331.18 13514942.19 -13943470.23 -85076422.98
## 161 162 163 164 165
## -89238503.63 13713944.20 8992415.43 5619097.12 2772891.14
## 166 167 168 169 170
## 22598873.70 8168263.56 10797622.12 -901131.82 1662038.84
## 171 172 173 174 175
## 6049943.84 1974534.27 11351638.83 5256415.42 4404862.98
## 176 177 178 179 180
## 22602486.38 11179792.40 5677808.71 6183924.58 -238287.29
## 181 182 183 184 185
## -13767755.74 16855860.58 7597860.32 10434485.41 26019997.97
## 186 187 188 189 190
## -6858254.78 13473912.13 12647334.26 7922890.65 5808037.82
## 191 192 193 194 195
## 3058739.93 14190724.52 8147069.62 14273349.15 3504366.47
## 196 197 198 199 200
## 5103201.85 6159949.47 17433057.26 16491645.74 -212430.92
## 201 202 203 204 205
## -5682617.55 18037688.51 278992122.99 3619902.46 149512818.84
## 206 207 208 209 210
## 5158127.54 19386.25 8255885.19 10413141.26 10404877.59
## 211 212 213 214 215
## 13621060.02 2489132.60 6089313.76 -76015.75 -5920498.74
## 216 217 218 219 220
## 21411628.07 9288121.67 12596261.11 64832050.27 7717988.12
## 221 222 223 224 225
## 42011432.59 514862.97 114089827.15 13174200.89 7066328.56
## 226 227 228 229 230
## 8609755.23 25812777.73 6177514.09 22873949.47 16866486.85
## 231 232 233 234 235
## 3537160.79 -7502300.16 10370470.96 -52690389.64 -56629789.77
## 236 237 238 239 240
## 28045462.60 28461325.55 -28210744.15 5589768.64 30918328.17
## 241 242 243 244 245
## -15006592.88 -36084167.73 -2274412.09 30123695.45 19675886.90
## 246 247 248 249 250
## -540779.16 21962016.91 -9691324.93 4133197.47 -16106504.52
## 251 252 253 254 255
## 20114974.34 -34371260.96 5668554.77 -17033239.88 -17706525.45
## 256 257 258 259 260
## 642218316.00 -17353873.95 -78689648.95 -5490725.02 1837619.50
## 261 262 263 264 265
## -137465203.94 -46875785.61 153165791.31 -177954517.69 -26439630.12
## 266 267 268 269 270
## -185723025.77 -3629524.23 -4639910.98 -51530190.44 -42693586.79
## 271 272 273 274 275
## -97215500.95 22889632.72 -51801227.80 -53458390.67 -107189454.08
## 276 277 278 279 280
## 7093029.32 -18154697.63 -144593189.62 -154973511.97 -48780136.64
## 281 282 283 284 285
## -49658826.87 -18251377.41 -14542883.33 -81176049.13 -26756467.04
## 286 287 288 289 290
## 5173165.60 -84331067.97 -85611970.13 -146598423.06 -13638614.20
## 291 292 293 294 295
## 1631928.68 -2156805.81 -3217363.96 9371744.43 864053.50
## 296 297 298 299 300
## -4802385.67 -13949198.80 -4930250.28 814693.22 -2276189.12
## 301 302 303 304 305
## -1489778.49 194553.58 2382951.82 12762314.09 334086.82
## 306 307 308 309 310
## -1938118.50 4184451.28 -7612148.29 -22025605.04 12627039.28
## 311 312 313 314 315
## -226966.19 4023218.07 16303945.02 -16082135.21 1564523.90
## 316 317 318 319 320
## 11987605.27 3056098.46 -4094449.43 -3404443.60 3772551.10
## 321 322 323 324 325
## 1704510.02 -760975.21 -1061649.66 -705420.21 -1303541.80
## 326 327 328 329 330
## 7829987.57 10994880.60 -15365573.50 -20564896.55 7374309.92
## 331 332 333 334 335
## 131978843.46 -5454448.06 61749951.24 4811042.31 -4792399.20
## 336 337 338 339 340
## -25605155.15 6126009.41 8947853.45 -23529803.45 -18521091.39
## 341 342 343 344 345
## 3373564.87 -13332867.68 -13284231.38 -1470316.54 1227586.20
## 346 347 348 349 350
## 3038232.29 11172434.04 -4314292.37 27593808.60 -12165005.37
## 351 352 353 354 355
## 26495461.28 10753691.84 1492977.70 -451970.56 -4228321.97
## 356 357 358 359 360
## 2853970.78 -20686136.30 7367274.96 -16910044.19 -45309280.55
## 361 362 363 364 365
## -13533476.63 -70336782.48 -124288929.46 12404616.98 20049071.58
## 366 367 368 369 370
## -63513048.30 -9751817.79 21581766.37 -21400818.23 -59922156.30
## 371 372 373 374 375
## -49979035.43 24772101.52 6436398.38 -16796176.41 6191551.45
## 376 377 378 379 380
## -18665225.78 -5380071.15 -32676663.86 9184024.53 -43501019.08
## 381 382 383 384
## -6075144.21 -20719928.08 -162104326.77 417127831.36
plot(mod$residuals)

#investigate the assumptions of the Expenditure~RVUs
#1)does depend var follow a normal distribution?
hist(Edata$Expenditures)

#this doesn't look normal distributed to me.
#there is extreme right skew. So we should do a log transformation
#2)Independence of observations (residuals)
mean(mod$residuals)
## [1] 1.720537e-09
#this assumption holds, the mean of the residuals is close to 0
#4)linear relationship between X and Y
cor(Expenditures, RVUs)
## [1] 0.9217239
#There is a positive and almost linear relationship, so this assumption is satisfied.
gvlma::gvlma(mod)
##
## Call:
## lm(formula = Edata$Expenditures ~ Edata$RVUs)
##
## Coefficients:
## (Intercept) Edata$RVUs
## -3785072.2 235.1
##
##
## ASSESSMENT OF THE LINEAR MODEL ASSUMPTIONS
## USING THE GLOBAL TEST ON 4 DEGREES-OF-FREEDOM:
## Level of Significance = 0.05
##
## Call:
## gvlma::gvlma(x = mod)
##
## Value p-value Decision
## Global Stat 15193.645 0.0000000 Assumptions NOT satisfied!
## Skewness 887.485 0.0000000 Assumptions NOT satisfied!
## Kurtosis 14287.478 0.0000000 Assumptions NOT satisfied!
## Link Function 11.946 0.0005478 Assumptions NOT satisfied!
## Heteroscedasticity 6.737 0.0094441 Assumptions NOT satisfied!
#Then fit a linear model of ln(Expenditures)~RVUs. How did this transformation affect the assumptions? I interpret this to mean do a log transform on the linear model and and then ask for the same summary stats and attributes.
#need to do a ln transform to fit the model
mod_fit_log = (ln(Edata$Expenditures)~Edata$RVUs)
plot((ln(Edata$Expenditures)~Edata$RVUs))
#add abline
abline(mod_fit_log, col = "darkorange", lwd = 2, untf=T)

summary(mod_fit_log)
## Length Class Mode
## 3 formula call
mod_fit_log$coef
## NULL
#Interprets ln(Expenditures)~RVU Regression
# it looks like there are Many undefined values after taking the log and so,the regression wont run.
#Investigates Regression Assumptions, ln(Expenditures)~RVUs
#earlier one of the assumptions was that we wanted to assume "normality" but the distribution wasn't normal. So a log transform can allow you to assume "normality" in some instances. Another assumption that changes a bit after taking the log is the mean and median. After doing a log transform, the mean and the median should be similar.
#Interpret the transformed regression