knitr::opts_chunk$set(echo = TRUE)
if (!require(ggplot2)) {
install.packages("ggplot2")
}
## Loading required package: ggplot2
if (!require(dplyr)) {
install.packages("dplyr")
}
## Loading required package: 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
if (!require(stats)) {
install.packages("stats")
}
library(ggplot2) library(dplyr) library(stats)
# Specify x-values for dnorm function
x_dnorm <- seq(-5, 5, by = 0.005)
y_dnorm <- dnorm(x_dnorm)
y_pnorm <- pnorm(x_dnorm)
x_qnorm <- seq(0, 1, by = 0.005)
y_qnorm <- qnorm(x_qnorm)
# Apply dnorm function
# Apply pnorm function
# Apply qnorm function
set.seed(123)
N <- 500
y_rnorm <- rnorm(N)
# combine plots
par(mfrow = c(2, 2))
plot(y_dnorm, main = "Density plot")
plot(y_pnorm, main = "Cumulative Density plot")
plot(y_qnorm, main = "Quantile plot")
plot(y_rnorm, main = "Scatter Plot Random Samples")
par(mfrow = c(1, 1))
# Specify x-values for dexp function
x_dexp <- seq(0, 1, by = 0.02)
y_dexp <- dexp(x_dexp, rate = 5)
y_pexp <- pexp(x_dexp, rate = 5)
x_qexp <- seq(0, 1, by = 0.02)
y_qexp <- qexp(x_qexp, rate = 5)
# Apply dexp function
# Apply pexp function
# Apply qexp function
set.seed(13579)
N <- 500
y_rexp <- rexp(N, rate = 5)
# combine plots
par(mfrow = c(2, 2))
plot(y_dexp, main = "Exp Density plot")
plot(y_pexp, main = "Exp Cumulative Density plot")
plot(y_qexp, main = "Exp Quantile plot")
plot(y_rexp, main = "Exp Scatter Plot Random Samples")
par(mfrow = c(1, 1))
# Specify x-values for dgamma function
x_dgamma <- seq(0, 1, by = 0.02)
y_dgamma <- dgamma(x_dgamma, shape = 5)
y_pgamma <- pgamma(x_dgamma, shape = 5)
y_qgamma <- qgamma(x_dgamma, shape = 5)
# Apply dgamma function
# Apply pgamma function
# Apply qgamma function
set.seed(13579)
N <- 500
y_rgamma <- rgamma(N, shape = 5)
# combine plots
par(mfrow = c(2, 2))
plot(y_dgamma, main = "Gamma Density plot")
plot(y_pgamma, main = "Gamma Cumulative Density plot")
plot(y_qgamma, main = "Gamma Quantile plot")
plot(y_rgamma, main = "Gamma Scatter Plot Random Samples")
par(mfrow = c(1, 1))
# Specify x-values for dbeta function
x_dbeta <- seq(0, 1, by = 0.02)
y_dbeta <- dbeta(x_dbeta, shape1 = 2, shape2 = 5)
y_pbeta <- pbeta(x_dbeta, shape1 = 2, shape2 = 5)
y_qbeta <- qbeta(x_dbeta, shape1 = 2, shape2 = 5)
# Apply dbeta function
# Apply pbeta function
# Apply qbeta function
set.seed(24680)
N <- 500
y_rbeta <- rbeta(N, shape1 = 2, shape2 = 5)
# combine plots
par(mfrow = c(2, 2))
plot(y_dbeta, main = "Beta Density plot")
plot(y_pbeta, main = "Beta Cumulative Density plot")
plot(y_qbeta, main = "Beta Quantile plot")
plot(y_rbeta, main = "Beta Scatter Plot Random Samples")
par(mfrow = c(1, 1))
# Specify x-values for dchisq function
x_dchisq <- seq(0, 20, by = 0.01)
y_dchisq <- dchisq(x_dchisq, df = 3)
y_pchisq <- pchisq(x_dchisq, df = 3)
x_dchisq <- seq(0, 1, by = 0.01)
y_qchisq <- qchisq(x_dchisq, df = 3)
# Set seed for reproducibility
set.seed(13579)
N <- 500
# Generate random samples
y_rchisq <- rchisq(N, df = 3)
y_rchisq
## [1] 9.40875055 2.39449258 0.47390375 0.61063988 3.05346606 0.76055155
## [7] 4.22813263 2.18121985 8.60938778 0.72189112 0.64786568 0.60733259
## [13] 3.85738502 5.25352396 1.02763548 2.50508821 1.81485216 3.34653065
## [19] 1.53994122 5.32058188 2.31422368 1.29958709 1.53846829 3.07388630
## [25] 5.03972548 4.60117189 3.99952446 0.77051536 11.09975361 2.87102132
## [31] 2.66297030 0.97438692 9.58511164 2.33491566 1.82202004 0.31053377
## [37] 1.16993670 1.53529001 2.17679004 0.24911057 4.50328189 4.07550909
## [43] 0.40882732 2.71601149 1.48556911 2.91149035 3.96544527 1.67145199
## [49] 1.83814128 10.84706357 4.66938441 4.02486494 0.76251372 8.73986979
## [55] 5.70158601 4.28402436 1.68905146 0.43773623 3.24213731 3.37263247
## [61] 0.24698024 3.69817912 4.80063458 0.55473343 0.89342037 2.72203575
## [67] 0.08623424 6.05450146 7.02666720 0.96049100 5.67837805 8.61924646
## [73] 1.35375731 1.80854914 0.69764473 2.83765195 5.25771695 2.41057643
## [79] 1.11184120 0.62286495 6.09394871 4.80252016 1.62857503 1.73419055
## [85] 4.92319878 1.80697406 5.31603368 0.19579514 4.38843740 2.75813422
## [91] 4.00974470 0.45875695 1.67968454 2.66826916 4.96100896 0.78192253
## [97] 1.22483829 4.63359608 9.14422962 3.26457746 6.11886265 2.66934759
## [103] 0.58634909 4.76454979 2.58500924 1.28933392 1.82988799 2.79782366
## [109] 5.10224022 2.26271269 3.23533157 1.96837213 4.55797867 2.45366481
## [115] 2.78623964 8.10259274 2.42613999 0.56502042 2.32045904 1.66553449
## [121] 1.46762928 2.65247223 0.47889745 1.30915620 2.75920500 2.41948240
## [127] 3.59027295 4.86424338 1.08212524 2.00504782 6.44897562 0.95514994
## [133] 4.94106405 2.09732089 0.14170620 2.71284398 1.44311908 1.73813129
## [139] 0.16362987 7.29436551 0.55050084 1.61259287 1.27948111 4.75469346
## [145] 0.57872591 2.05315443 4.54302047 0.98521294 2.68879334 3.94491626
## [151] 1.68234630 1.64471538 1.14256421 6.57604073 8.61550038 3.70421549
## [157] 6.91122006 1.37971364 2.17300697 1.56100089 1.40502243 3.13862807
## [163] 5.12983401 1.65367214 1.75403713 0.43769853 6.01507458 1.62878151
## [169] 1.48207507 0.20140100 0.75355260 3.70300291 5.71393906 2.35147853
## [175] 3.78689980 2.87434325 5.33529802 3.50729683 4.39108038 0.95995393
## [181] 1.46142662 2.22823674 3.59526631 0.35364592 5.50534980 2.00616905
## [187] 4.31321548 1.65105986 2.82351005 2.04212295 3.33770802 1.06056483
## [193] 3.27196332 10.26585822 3.21413594 1.88555689 2.98764668 5.33299335
## [199] 0.89450408 0.14272733 12.37941712 1.50134073 1.88723251 1.23757404
## [205] 7.44252558 5.25712210 0.66368283 6.50434193 0.34326324 2.77502006
## [211] 1.64567030 0.96518556 3.70368460 4.06409428 3.83572403 1.86725197
## [217] 4.07504842 4.96934595 0.96060553 1.83357930 2.06380655 1.99110640
## [223] 2.85363432 1.84919636 6.07530162 1.15887268 4.74273662 4.05098834
## [229] 2.78334812 6.60366867 4.42457647 6.46911889 1.88190257 1.30509407
## [235] 4.44786060 2.64429315 6.22834731 4.49125663 3.19874276 1.75182019
## [241] 2.74365686 2.87658283 4.03175534 2.25393665 0.34867833 3.28062628
## [247] 1.08382098 3.05832296 0.61140000 0.84739619 0.06916182 4.55163499
## [253] 1.89447981 3.17310550 1.64190736 6.27133478 1.94353395 0.36536351
## [259] 11.43281605 2.84261702 0.47264031 0.21345420 1.76941064 9.05192457
## [265] 1.67488721 3.06676889 1.54592061 1.54252576 8.21569440 3.44653629
## [271] 0.61142602 2.45363230 1.96786170 5.08668112 10.91033243 0.87495420
## [277] 7.59095400 1.13252367 2.91214090 2.30518633 0.60818915 0.40056714
## [283] 1.90707014 2.05440314 2.01931560 0.84046939 2.37367838 5.18537588
## [289] 7.42067081 3.67846312 1.05225825 1.58791362 6.64439628 5.35359710
## [295] 6.16092871 2.75834116 0.50649665 1.56081242 3.10216977 3.36822383
## [301] 2.04978656 5.14793534 0.32135644 4.16446275 4.89426116 0.36479863
## [307] 1.09238204 1.22785925 2.31187268 3.18676316 2.71610860 0.29451038
## [313] 3.34124506 5.73558789 0.88006749 2.23945583 0.75896752 2.69230938
## [319] 1.39445491 0.68600927 6.46720639 0.32457497 6.16194856 3.36246320
## [325] 0.95280092 1.87507381 0.91296744 0.17341532 0.93230551 8.01506002
## [331] 2.22132303 1.76855577 0.32680574 1.55297357 2.37164795 4.67099439
## [337] 5.47919441 1.96202854 1.50609117 4.53360140 0.39519184 1.11236453
## [343] 0.28010174 1.32530773 0.22717598 1.53055254 4.93143765 2.15666910
## [349] 3.71864708 3.62219243 0.98808060 2.36746244 0.31068685 1.27407609
## [355] 3.05935082 2.07381453 6.98316264 4.16332313 1.21919812 1.74032200
## [361] 5.31322981 0.71298834 2.45722527 2.56677598 3.39361980 1.68719617
## [367] 3.64543733 1.60842628 1.26145291 7.99994961 0.51836418 0.42602713
## [373] 2.60605595 3.66170012 4.60457431 5.38959526 0.32303946 7.39590159
## [379] 4.63380827 2.86797763 6.73257721 5.02217780 4.54290862 1.72781440
## [385] 2.55165773 0.51903319 7.20794861 4.27637990 6.97893764 5.27277277
## [391] 0.08424638 6.15941751 2.84354613 1.71553448 4.96513986 2.40313404
## [397] 4.65908322 0.91652584 2.35900077 2.18638557 2.38334553 1.47638425
## [403] 4.14813242 2.91230746 1.97241802 0.44100204 3.02057861 2.86459387
## [409] 4.68297548 1.14348297 0.53490983 3.88500157 2.62846223 3.26888076
## [415] 5.05340695 1.71472359 0.46968665 0.58776463 2.73643733 4.06736212
## [421] 3.20706821 1.40642997 2.02054134 3.36314973 1.85166814 2.93743693
## [427] 1.03219509 0.70642856 7.83573200 2.95669980 3.38391454 5.83193738
## [433] 3.10288614 1.05020945 2.89051613 2.35347553 4.76565805 2.84822843
## [439] 2.39680408 3.25089192 3.40390938 4.74646909 1.45606493 1.41568068
## [445] 0.59590329 9.34740023 0.49047683 5.19266202 0.64214743 0.38472440
## [451] 7.80086877 0.82916509 0.76496724 2.59823113 5.60805953 0.89121768
## [457] 4.84986579 0.14638504 6.15821231 0.51456229 3.07447494 2.09832538
## [463] 2.48757543 3.03690522 11.95474282 5.80105280 2.90603751 2.51528917
## [469] 0.53151149 0.82663654 3.24340917 7.98116945 1.17568590 3.16492180
## [475] 3.20115112 0.38249294 7.52764504 2.46744016 2.66668296 8.71035257
## [481] 1.10757543 1.89540619 2.85836319 1.95992748 0.34443267 2.26796444
## [487] 4.72284239 3.64465760 0.62915959 9.69228171 8.18372736 3.82590431
## [493] 0.58277129 14.54554407 1.52259235 5.60318348 6.75510659 3.74061509
## [499] 0.38593359 0.84105710
# Combine plots
par(mfrow = c(2, 2))
plot(y_dchisq, main = "Chi Square Density plot")
plot(y_pchisq, main = "Chi Square Cumulative Density plot")
plot(y_qchisq, main = "Chi Square Quantile plot")
plot(y_rchisq, main = "Chi Square Scatter Plot Random Samples")
par(mfrow = c(1, 2))
plot(density(y_rchisq), main = "Density plot")
hist(y_rchisq, main = "Histogram")
par(mfrow = c(1, 1))
# Modify values of the shape parameter
y_rchisq2 <- rchisq(N, df = 1)
y_rchisq3 <- rchisq(N, df = 2)
# Plot density with higher mean
lines(density(y_rchisq2), col = "coral2", lwd = 3)
# Plot density with higher sd
lines(density(y_rchisq3), col = "green3", lwd = 3)
# Add legend to the plot
legend("topright",
legend = c("df = 3", "df = 1", "df = 2"),
col = c("black", "coral2", "green3"),
lty = 2, lwd = 3,
title = "Chi Square Distribution in R with different degrees of freedom")
# Specify x-values for dt function
x_dt <- seq(-4, 4, by = 0.01)
y_dt <- dt(x_dt, df = 1)
y_pt <- pt(x_dt, df = 1)
x_dt <- seq(0, 1, by = 0.01)
y_qt <- qt(x_dt, df = 1)
# Set seed for reproducibility
set.seed(91929)
N <- 500
# Generate random samples
y_rt <- rt(N, df = 1)
y_rt
## [1] -0.206680813 0.687827774 0.097775011 -0.320853310 0.732752143
## [6] 0.239506538 0.829111987 -0.968523712 2.943826284 1.286777777
## [11] -2.267263824 1.354351052 4.312681123 1.080469914 0.638726100
## [16] -1.419955543 -0.243128132 0.053082008 1.406649321 21.815783201
## [21] -1.626295490 -4.601582677 0.834281511 -11.004810264 2.934937810
## [26] -0.336454957 -0.831258982 3.958851185 1.662298533 -0.882703587
## [31] -0.810382620 0.681780649 -2.446399374 0.758066790 -0.213445168
## [36] -0.743516359 -3.783991229 0.412218027 0.342464072 -0.484595660
## [41] 0.263298603 -1.136493441 -0.419313003 -0.027935552 2.297732156
## [46] -0.831028673 -1.506974454 1.845560699 -2.443561862 0.302679257
## [51] 1.651117050 1.356164125 -2.405459421 -2.968223150 0.599379697
## [56] 4.662295938 -0.065611122 -57.858327769 0.517822423 0.958256365
## [61] 5.081258054 0.866385715 -0.856753660 -0.515367493 -2.781923327
## [66] 0.745971073 -0.711160846 0.305279358 0.991753204 -1.877920271
## [71] -1.164522911 -1.411948308 -1.173261105 22.539142063 0.092592839
## [76] -0.376208135 -1.116272186 0.470584966 0.195007956 0.040906665
## [81] 2.142722847 -0.543800768 -0.307655882 0.452904062 0.032532871
## [86] 10.045834946 -0.860729053 0.256368832 0.871727596 1.661314283
## [91] -1.364645917 -2.048647859 -0.503850398 1.372356305 0.118479068
## [96] -1.043361194 0.059507279 -3.133569916 -2.560703884 0.275265477
## [101] -17.779647582 -0.037759774 -2.452026380 -0.157049897 1.514400946
## [106] 0.992970158 0.001793779 -0.911563907 0.769091996 -5.187242304
## [111] 0.969133332 -3.188563317 -6.411608287 0.956685119 0.253864046
## [116] 3.104547101 -0.340563096 1.241340681 0.976833115 -0.163751529
## [121] -69.212656517 0.798819936 -0.569308621 2.122199979 0.276846670
## [126] -3.191976010 6.981356152 2.342004740 0.569817964 -0.300670837
## [131] -0.872034108 -0.261438268 -0.514416741 -35.153470607 0.355096217
## [136] -1.279621823 0.861112020 1.531298364 -15.570277094 4.163489529
## [141] 0.289727931 -6.183919796 -0.008553019 0.704877833 -2.255252963
## [146] 1.143218823 -0.159396613 -0.750181313 -0.049703891 -1.841100844
## [151] -0.659551461 -0.061989428 -5.940545081 7.130882237 -0.792777384
## [156] 0.828461014 -1.037788914 2.541578804 -1.772900612 -0.424425728
## [161] 0.365794488 0.810918845 5.133561129 -4.377453918 -2.542577584
## [166] 0.932951022 0.003141469 -14.466151581 -3.236182668 -0.023161614
## [171] 1.824483762 -1.130040037 8.455279721 -2.057023129 -0.654306517
## [176] -89.802125908 0.025733970 -0.143730802 0.188770469 3.219218085
## [181] -1.133995562 -18.010875564 -1.234131948 -5.831395356 -1.163073196
## [186] 0.054316248 -0.645063743 0.136374130 1.434427137 -0.797505939
## [191] -0.898280717 -0.303451497 3.053033570 -0.841088721 0.158698074
## [196] -0.639101926 -0.336934985 2.134087611 -0.124843443 0.322523503
## [201] -1.077315354 0.540014222 -1.099033931 -0.944349095 0.864301460
## [206] -2.573287892 1.253949450 -1.874308678 1.020442939 -0.809357520
## [211] 0.147526588 2.225650676 17.298929966 -1.034743547 -1.207669329
## [216] -0.070569855 -1.033665770 -3.331253679 0.327824305 4.646954918
## [221] 0.466907147 0.257442142 -9.450080050 -7.308687659 -0.070353159
## [226] -0.762487117 0.019082420 0.266731898 -37.050448609 -4.388492330
## [231] -0.225683481 0.433180501 -1.389130481 0.056516928 -0.998932951
## [236] 1.639358332 -0.185068634 -1.923429067 0.783143766 1.488517093
## [241] -0.265340417 0.855835109 -0.704330760 -0.332917204 -2.644690384
## [246] -0.767778952 -0.634889591 2.209728366 -0.517589213 -0.560293415
## [251] 0.270160407 -1.018048931 3.611526569 -0.249010015 0.023089390
## [256] 0.363967699 2.794213653 0.338758245 2.525812345 -0.209189141
## [261] -2.620461248 0.352409996 -1.571301110 -2.669684838 -0.313992662
## [266] 0.833009866 -1.009821277 -4.639706497 -4.673463929 0.263971348
## [271] 0.561915529 0.572049811 0.585682412 4.493790848 1.517192256
## [276] -0.107479021 0.744448215 -2.201648909 -2.738124294 0.911005998
## [281] 64.986470660 -0.582820713 -1.300450490 -0.853042511 13.487568471
## [286] 1.101078664 15.017409025 -0.781973640 1.697885045 -2.031655557
## [291] -0.639941338 11.213121968 0.748636642 0.392709755 43.156220804
## [296] -0.796788740 0.263809507 -2.385826898 -3.865203484 -2.193934971
## [301] -0.893555618 -1.373922729 0.270707205 -0.167941033 -0.763187127
## [306] 1.401406555 -0.661468077 0.194387326 -0.707461479 0.879387341
## [311] -0.277529822 -0.774965318 -0.677816557 1.080948709 -2.053349443
## [316] 0.125442589 1.233581061 -0.042285071 -0.947610248 3.171778911
## [321] -0.273497251 -0.948441068 -0.232044636 -0.251481896 2.797206862
## [326] 25.604272309 -1.612933594 -8.313805663 0.782409742 0.503845835
## [331] 1.717264262 -0.211119465 -0.450656488 12.096533809 1.141202622
## [336] 0.479245855 8.187343726 -23.480757861 6.311975506 -0.573019748
## [341] 1.199550609 -0.273482269 1.227576810 -0.390158805 -2.816412147
## [346] -0.994995877 -9.023201355 -0.706133178 -0.032878847 -0.189608409
## [351] -6.530603310 0.447348177 0.163341145 1.029268620 -1.267392222
## [356] -0.005770871 -0.142437235 -10.946535408 -2.225425628 1.628219049
## [361] 1.227526223 -0.203279674 -1.156827252 -0.067503263 0.998504927
## [366] 0.046978003 0.238632071 1.715813142 -1.173942188 0.432433159
## [371] -1.523187763 0.457026892 3.846948669 -1.645788299 3.603034105
## [376] -4.539786623 -0.143735278 -0.870343937 -0.038701559 -0.086102021
## [381] 0.358450297 1.244308046 0.127274384 1.360470272 -1.265838454
## [386] 0.430305657 0.496592038 -3.244543945 -5.480050034 4.184942539
## [391] 15.065429777 0.235285626 0.855682649 -0.527824646 0.072696463
## [396] 0.029171955 -0.548077317 0.638290935 -2.169507974 -0.190727397
## [401] 0.800164261 -12.792040079 -0.228393666 -2.067483607 1.173279448
## [406] 0.305630175 -0.443008229 0.265011804 0.900396731 0.569747467
## [411] 5.455293066 0.237078198 -3.202576645 1.375390521 -6.138395517
## [416] 1.809315614 6.095788560 0.335552067 0.216036955 0.093069903
## [421] -1.256168007 0.506617199 -0.643834955 -1.829273486 -0.371929968
## [426] 0.521663592 -0.250761985 -0.715996337 1.797463823 1.149033305
## [431] -1.192012209 -0.632049618 0.196927733 0.368302959 -0.107413518
## [436] 0.707572596 5.544136495 -0.067094422 1.925835267 -1.361592172
## [441] -0.883908826 1.460600287 0.304226405 -0.214359444 -0.711777526
## [446] -1.081616451 0.751022597 30.704746025 34.692301254 2.269407396
## [451] -0.450654504 0.573028909 -0.018551563 1.884073099 -0.218305514
## [456] -0.232918146 0.212579426 3.758713754 -2.187723937 -1.118910572
## [461] -0.623292070 -0.139470191 -0.709325966 1.828023144 -0.227666349
## [466] 0.084369030 -0.245359717 2.026907211 -0.269000414 -0.496034855
## [471] 1.727497655 1.280743082 0.153837527 0.618625551 -2.142471555
## [476] 0.186357444 1.219821528 -2.290075193 -0.736552099 10.473227893
## [481] 4.059547630 1.088285292 2.141971154 -6.087338082 3.610167580
## [486] 2.564431495 -0.830389061 1.506793629 -7.888067967 0.217169451
## [491] 0.181352285 -1.324075549 -4.797856772 -3.421591680 0.431135030
## [496] 0.363778505 -1.318554561 0.676659199 0.773356186 -1.159720300
# Combine plots
par(mfrow = c(2, 2))
plot(y_dt, main = "Students t Density plot")
plot(y_pt, main = "Students t Cumulative Density plot")
plot(y_qt, main = "Students t Quantile plot")
plot(y_rt, main = "Students t Scatter Plot Random Samples")
par(mfrow = c(1, 1))
plot(density(y_rt), main = "Density plot", xlim = c(-4, 10))
hist(y_rt, main = "Histogram", breaks = 1000, xlim = c(-3, 3))
par(mfrow = c(1, 1))
# Modify values of the shape parameter
y_rt2 <- rchisq(N, df = 2)
y_rt3 <- rchisq(N, df = 3)
# Plot density with higher mean
lines(density(y_rt2), col = "coral2", lwd = 3)
# Plot density with higher sd
lines(density(y_rt3), col = "green3", lwd = 3)
# Add legend to the plot
legend("topright",
legend = c("df = 1", "df = 2", "df = 3"),
col = c("black", "coral2", "green3"),
lty = 2, lwd = 3,
title = "Students t Distribution in R with different degrees of freedom")
# Specify x-values for df function
x_df <- seq(0, 20, by = 0.01)
y_df <- df(x_df, df1 = 3, df2 = 5) # Apply df function
y_pf <- pf(x_df, df1 = 30, df2 = 5) # Apply pf function
# Plot density
plot(y_df, main = "F Density plot")
# Plot cumulative density
plot(y_pf, main = "F Cumulative Density plot")
# Specify x-values for qf function
x_qf <- seq(0, 1, by = 0.01)
y_qf <- qf(x_qf, df1 = 3, df2 = 5) # Apply qf function
# Set seed for reproducibility
set.seed(13579)
N <- 500
# Generate random samples
y_rf <- rf(N, df1 = 3, df2 = 5)
# Plot quantile
plot(y_qf, main = "F Quantile plot")
# Plot scatter plot of random samples
plot(y_rf, main = "F Scatter Plot Random Samples")
# Combine density and histogram plots
par(mfrow = c(1, 2))
plot(density(y_rf), main = "Density plot")
hist(y_rf, main = "Histogram")
par(mfrow = c(1, 1))
# Modify values of the shape parameter
y_rf2 <- rf(N, df1 = 10, df2 = 6)
y_rf3 <- rf(N, df1 = 20, df2 = 7)
# Plot density with higher mean
lines(density(y_rf2), col = "coral2", lwd = 3)
# Plot density with higher sd
lines(density(y_rf3), col = "green3", lwd = 3)
# Add legend to the plot
legend("topright",
legend = c("Shape1 = 2, Shape2 = 5",
"Shape1 = 10, Shape2 = 6",
"Shape1 = 20, Shape2 = 7"),
col = c("black", "coral2", "green3"),
lty = 2, lwd = 3,
title = "F Probability Distributions in R with different degrees of freedom")
# Specify x-values for dunif function
x_dunif <- seq(0, 100, by = 1)
y_dunif <- dunif(x_dunif, min = 10, max = 50)
y_punif <- punif(x_dunif, min = 10, max = 50)
# Specify x-values for qunif function
x_qunif <- seq(0, 1, by = 0.01)
y_qunif <- qunif(x_qunif, min = 10, max = 50)
# Set seed for reproducibility
set.seed(13579)
N <- 500
# Generate random samples
y_runif <- runif(N, min = 10, max = 50)
# Plot density
plot(y_dunif, main = "Uniform Continuous Density plot")
# Plot cumulative density
plot(y_punif, main = "Uniform Continuous Cumulative Density plot")
# Plot quantile
plot(y_qunif, main = "Uniform Continuous Quantile plot")
# Plot scatter plot of random samples
plot(y_runif, main = "Uniform Continuous Scatter Plot Random Samples")
# Combine density and histogram plots
par(mfrow = c(1, 2))
plot(density(y_runif), main = "Density plot")
hist(y_runif, main = "Histogram")
par(mfrow = c(1, 1))
# Modify values of the shape parameter
y_runif2 <- runif(N, min = 10, max = 60)
y_runif3 <- runif(N, min = 10, max = 70)
# Plot density with higher mean
lines(density(y_runif2), col = "coral2", lwd = 3)
# Plot density with higher sd
lines(density(y_runif3), col = "green3", lwd = 3)
# Add legend to the plot
legend("topright",
legend = c("Min = 10, Max = 50",
"Min = 10, Max = 60",
"Min = 10, Max = 70"),
col = c("black", "coral2", "green3"),
lty = 2, lwd = 3,
title = "Uniform Continuous Distribution in R")
# Specify x-values for dbinom function
x_dbinom <- seq(0, 100, by = 1)
y_dbinom <- dbinom(x_dbinom, size = 100, prob = 0.5)
y_pbinom <- pbinom(x_dbinom, size = 100, prob = 0.5)
x_qbinom <- seq(0, 1, by = 0.01)
y_qbinom <- qbinom(x_qbinom, size = 100, prob = 0.5)
set.seed(13579)
N <- 500
y_rbinom <- rbinom(N, size = 100, prob = 0.5)
y_rbinom
# Combine plots
par(mfrow=c(2,2))
plot(y_dbinom, main="Binomial Density plot")
plot(y_pbinom, main="Binomial Cumulative Density plot")
plot(y_qbinom, main="Binomial Quantile plot")
plot(y_rbinom, main="Binomial Scatter Plot Random Samples")
par(mfrow=c(1,2))
plot(density(y_rbinom), main="Density plot")
hist(y_rbinom, main="Histogram")
par(mfrow=c(1,1))
# Modify values of the probability parameter
y_rbinom2 <- rbinom(N, size = 100, prob = 0.7)
y_rbinom3 <- rbinom(N, size = 100, prob = 0.3)
# Plot density with higher mean
lines(density(y_rbinom2), col = "coral2", lwd = 3)
# Plot density with higher sd
lines(density(y_rbinom3), col = "green3", lwd = 3)
# Add legend to the plot
legend("topright",
legend = c("P Value = 0.5", "P Value = 0.7", "P Value = 0.3"),
col = c("black", "coral2", "green3"),
lty = 2, lwd = 3,
title = "Binomial Distribution in R with different probability values")
# Specify x-values for dpois function
x_dpois <- seq(-5, 30, by = 1)
y_dpois <- dpois(x_dpois, lambda = 10)
y_ppois <- ppois(x_dpois, lambda = 10)
x_qpois <- seq(0, 1, by = 0.005)
y_qpois <- qpois(x_qpois, lambda = 10)
set.seed(13579)
N <- 500
y_rpois <- rpois(N, lambda = 10)
y_rpois
# Combine plots
par(mfrow=c(2,2))
plot(y_dpois, main="Poisson Density plot")
plot(y_ppois, main="Poisson Cumulative Density plot")
plot(y_qpois, main="Poisson Quantile plot")
plot(y_rpois, main="Poisson Scatter Plot Random Samples")
par(mfrow=c(1,2))
plot(density(y_rpois), main="Density plot")
hist(y_rpois, main="Histogram")
par(mfrow=c(1,1))
# Modify values of the lambda parameter
y_rpois2 <- rpois(N, lambda = 15)
y_rpois3 <- rpois(N, lambda = 20)
# Plot density with higher mean
lines(density(y_rpois2), col = "coral2", lwd = 3)
# Plot density with higher sd
lines(density(y_rpois3), col = "green3", lwd = 3)
# Add legend to the plot
legend("topright",
legend = c("lambda = 10", "lambda = 15", "lambda = 20"),
col = c("black", "coral2", "green3"),
lty = 2, lwd = 3,
title = "Poisson Distribution in R with different lambda values")
# Specify x-values for dgeom function
x_dgeom <- seq(0, 20, by = 1)
y_dgeom <- dgeom(x_dgeom, prob = 0.5)
y_pgeom <- pgeom(x_dgeom, prob = 0.5)
x_qgeom <- seq(0, 1, by = 0.01)
y_qgeom <- qgeom(x_qgeom, prob = 0.5)
set.seed(13579)
N <- 500
y_rgeom <- rgeom(N, prob = 0.5)
y_rgeom
# Combine plots
par(mfrow=c(2,2))
plot(y_dgeom, main="Geometric Density plot")
plot(y_pgeom, main="Geometric Cumulative Density plot")
plot(y_qgeom, main="Geometric Quantile plot")
plot(y_rgeom, main="Geometric Scatter Plot Random Samples")
par(mfrow=c(1,2))
plot(density(y_rgeom), main="Density plot")
hist(y_rgeom, main="Histogram")
par(mfrow=c(1,1))
# Modify values of the probability parameter
y_rgeom2 <- rgeom(N, prob = 0.7)
y_rgeom3 <- rgeom(N, prob = 0.3)
# Plot density with higher mean
lines(density(y_rgeom2), col = "coral2", lwd = 3)
# Plot density with higher sd
lines(density(y_rgeom3), col = "green3", lwd = 3)
# Add legend to the plot
legend("topright",
legend = c("P value = 0.5", "P value = 0.7", "P value = 0.3"),
col = c("black", "coral2", "green3"),
lty = 2, lwd = 3,
title = "Geometric Distribution in R with different probability values")
# Specify x-values for dnbinom function
x_dnbinom <- seq(0, 100, by = 1)
y_dnbinom <- dnbinom(x_dnbinom, size = 100, prob = 0.5)
y_pnbinom <- pnbinom(x_dnbinom, size = 100, prob = 0.5)
x_dnbinom <- seq(0, 1, by = 0.01)
y_qnbinom <- qnbinom(x_dnbinom, size = 100, prob = 0.5)
set.seed(13579)
N <- 500
y_rnbinom <- rnbinom(N, size = 100, prob = 0.5)
y_rnbinom
# Combine plots
par(mfrow=c(2,2))
plot(y_dnbinom, main="Negative Binomial Density plot")
plot(y_pnbinom, main="Negative Binomial Cumulative Density plot")
plot(y_qnbinom, main="Negative Binomial Quantile plot")
plot(y_rnbinom, main="Negative Binomial Scatter Plot Random Samples")
par(mfrow=c(1,2))
plot(density(y_rnbinom), main="Density plot")
hist(y_rnbinom, main="Histogram")
par(mfrow=c(1,1))
# Modify values of the probability parameter
y_rnbinom2 <- rnbinom(N, size = 100, prob = 0.7)
y_rnbinom3 <- rnbinom(N, size = 100, prob = 0.3)
# Plot density with higher mean
lines(density(y_rnbinom2), col = "coral2", lwd = 3)
# Plot density with higher sd
lines(density(y_rnbinom3), col = "green3", lwd = 3)
# Add legend to the plot
legend("topright",
legend = c("P value = 0.5", "P value = 0.7", "P value = 0.3"),
col = c("black", "coral2", "green3"),
lty = 2, lwd = 3,
title = "Negative Binomial Distribution in R with different probability values")