x_dnorm <- seq(- 5, 5, by = 0.005) y_dnorm <- dnorm(x_dnorm) # Apply dnorm function y_pnorm <- pnorm(x_dnorm) # apply pnorm function x_qnorm <- seq(0, 1, by = 0.005) y_qnorm <- qnorm(x_qnorm) # apply qnorm function set.seed(123) # mark reference point for random sampling N = 500 # Number of random samples needed y_rnorm <- rnorm(N) # Draw N normally distributed values y_rnorm # 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,2)) plot(density(y_rnorm),main = “Density plot”) hist(y_rnorm, main= “Histogram”) par(mfrow=c(1,1)) ## Modify values of the mean and sd y_rnorm2 <- rnorm(N, mean = 2) # Modify mean y_rnorm3 <- rnorm(N, mean = 2, sd = 3) # Modify standard deviation plot(density(y_rnorm), # Plot default density xlim = c(- 10, 10), main = “Normal Distribution in R with different Mean and SD”,lwd=3) lines(density(y_rnorm2), col = “coral2”,lwd=3) # Plot density with higher mean lines(density(y_rnorm3), col = “green3”,lwd=3) # Plot density with higher sd legend(“topleft”, # Add legend to density legend = c(“Mean = 0; SD = 1”, “Mean = 2; SD = 1”, “Mean = 2; SD = 3”), col = c(“black”, “coral2”, “green3”),lty = 2, lwd=3) par(mfrow=c(1,1))
x_dexp <- seq(0, 1, by = 0.02) y_dexp <- dexp(x_dexp, rate = 5) # Apply dexp function y_pexp <- pexp(x_dexp, rate = 5) # Apply pexp function x_qexp <- seq(0, 1, by = 0.02) # Specify x-values for qexp function y_qexp <- qexp(x_qexp, rate = 5) # Apply qexp function set.seed(13579) # Set seed for reproducibility N <- 500 # Specify sample size y_rexp <- rexp(N, rate = 5) # Draw N exp distributed values y_rexp # Print values to RStudio console # 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,2)) par(mfrow=c(1,2)) plot(density(y_rexp),main = “Density plot”) hist(y_rexp, main= “Histogram”) par(mfrow=c(1,1)) ## Modify values of the mean and sd y_rexp2 <- rexp(N, rate = 4) # Modify rate parameter y_rexp3 <- rexp(N, rate = 3) # Modify rate parameter plot(density(y_rexp), # Plot default density xlim = c(- 0, 2), main = “Exponential Distribution in R with different Rates”,lwd=3) lines(density(y_rexp2), col = “coral2”,lwd=3) # Plot density with higher mean lines(density(y_rexp3), col = “green3”,lwd=3) # Plot density with higher sd legend(“topright”, # Add legend to density legend = c(“Rate = 5”, “Rate = 1”, “Rate = 7”), col = c(“black”, “coral2”, “green3”),lty = 2, lwd=3) par(mfrow=c(1,1))
x_dgamma <- seq(0, 1, by = 0.02) y_dgamma <- dgamma(x_dgamma, shape = 5) # Apply dgamma function y_pgamma <- pgamma(x_dgamma, shape = 5) # Apply pgamma function y_qgamma <- qgamma(x_dgamma, shape = 5) # Apply qexp function set.seed(13579) # Set seed for reproducibility N <- 500 # Specify sample size y_rgamma <- rgamma(N, shape = 5) # Draw N exp distributed values y_rgamma # Print values to RStudio console # 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,2)) par(mfrow=c(1,2)) plot(density(y_rgamma),main = “Density plot”) hist(y_rgamma, main= “Histogram”) par(mfrow=c(1,1)) ## Modify values of the shape parameter y_rgamma2 <- rgamma(N, shape = 2) # Modify shape parameter y_rgamma3 <- rgamma(N, shape = 3) # Modify shape parameter plot(density(y_rgamma), # Plot default density xlim = c(- 0, 10), ylim = c(- 0, .35), main = “Gamma Distribution in R with different Shapes”,lwd=3) lines(density(y_rgamma2), col = “coral2”,lwd=3) # Plot density with higher mean lines(density(y_rgamma3), col = “green3”,lwd=3) # Plot density with higher sd legend(“topright”, # Add legend to density legend = c(“Shape = 5”, “Shape = 2”, “Shape = 3”), col = c(“black”, “coral2”, “green3”),lty = 2, lwd=3) par(mfrow=c(1,1))
x_dbeta <- seq(0, 1, by = 0.02) y_dbeta <- dbeta(x_dbeta, shape1 = 2, shape2 =5) # Apply dbeta function y_pbeta <- pbeta(x_dbeta, shape1 = 2, shape2 =5) # Apply pbeta function y_qbeta <- qbeta(x_dbeta, shape1 = 2, shape2 =5) # Apply qbeta function set.seed(13579) # Set seed for reproducibility N <- 500 # Specify sample size y_rbeta <- rbeta(N, shape1 = 2, shape2 = 5) # Draw N exp distributed values # combine plots par(mfrow=c(2,2)) plot(y_dbeta, main=“Gamma Density plot”) plot(y_pbeta, main=“Gamma Cumulative Density plot”) plot(y_qbeta, main=“Gamma Quantile plot”) plot(y_rbeta, main=“Gamma Scatter Plot Random Samples”) par(mfrow=c(1,2)) par(mfrow=c(1,2)) plot(density(y_rbeta),main = “Density plot”) hist(y_rbeta, main= “Histogram”) par(mfrow=c(1,1)) ## Modify values of the shape parameter y_rbeta2 <- rbeta(N, shape1 = 5, shape2 = 2) # Modify shape parameter y_rbeta3 <- rbeta(N, shape1 = 7, shape2 = 7) # Modify shape parameter plot(density(y_rbeta), # Plot default density xlim = c(- 0, 2), ylim = c(- 0, 3), main = “Gamma Distribution in R with different Shapes”,lwd=3) lines(density(y_rbeta2), col = “coral2”,lwd=3) # Plot density with higher mean lines(density(y_rbeta3), col = “green3”,lwd=3) # Plot density with higher sd legend(“topright”, # Add legend to density legend = c(“Shape1 = 2, shape2=5”, “Shape1 = 5, shape2=2”, “Shape1 = 7, shape2=7”), col = c(“black”, “coral2”, “green3”),lty = 2, lwd=3) par(mfrow=c(1,1))
x_dchisq <- seq(0, 20, by = 0.01) y_dchisq <- dchisq(x_dchisq, df = 3) # Apply dgamma function y_pchisq <- pchisq(x_dchisq, df = 3) # Apply pgamma function x_dchisq <- seq(0, 1, by = 0.01) y_qchisq <- qchisq(x_dchisq, df = 3) # Apply qexp function set.seed(13579) # Set seed for reproducibility N <- 500 # Specify sample size y_rchisq <- rchisq(N, df = 3) # Draw N exp distributed values y_rchisq # Print values to RStudio console # 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=“chisq Scatter Plot Random Samples”) par(mfrow=c(1,2)) 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) # Modify shape parameter y_rchisq3 <- rchisq(N, df = 2) # Modify shape parameter plot(density(y_rchisq), # Plot default density xlim = c(- 0, 10), ylim = c(- 0, 1.1), main = “Chi Square Distribution in R with different degrees of freedom”,lwd=3) lines(density(y_rchisq2), col = “coral2”,lwd=3) # Plot density with higher mean lines(density(y_rchisq3), col = “green3”,lwd=3) # Plot density with higher sd legend(“topright”, # Add legend to density legend = c(“df = 3”, “df = 1”, “df = 2”), col = c(“black”, “coral2”, “green3”),lty = 2, lwd=3) par(mfrow=c(1,1))
x_dt <- seq(-4, 4, by = 0.01) y_dt <- dt(x_dt, df = 1) # Apply dgamma function y_pt <- pt(x_dt, df = 1) # Apply pgamma function x_dt <- seq(0, 1, by = 0.01) y_qt <- qt(x_dt, df = 1) # Apply qexp function set.seed(91929) # Set seed for reproducibility N <- 500 # Specify sample size y_rt <- rt(N, df = 1) # Draw N exp distributed values y_rt # Print values to RStudio console # 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) # Modify shape parameter y_rt3 <- rchisq(N, df = 3) # Modify shape parameter plot(density(y_rt), # Plot default density xlim = c(-4, 10), main = “Students t Distribution in R with different degrees of freedom”,lwd=3) lines(density(y_rt2), col = “coral2”,lwd=3) # Plot density with higher mean lines(density(y_rt3), col = “green3”,lwd=3) # Plot density with higher sd legend(“topright”, # Add legend to density legend = c(“df = 1”, “df = 2”, “df = 3”), col = c(“black”, “coral2”, “green3”),lty = 2, lwd=3) par(mfrow=c(1,1))
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 x_df <- seq(0, 1, by = 0.01) y_qf <- qf(x_df, df1 = 3, df2 =5) # Apply qf function set.seed(13579) # Set seed for reproducibility N <- 500 # Specify sample size y_rf <- rf(N, df1 = 3, df2 = 5) # Draw N exp distributed values # combine plots par(mfrow=c(2,2)) plot(y_df, main=“Gamma Density plot”) plot(y_pf, main=“Gamma Cumulative Density plot”) plot(y_qf, main=“Gamma Quantile plot”) plot(y_rf, main=“Gamma Scatter Plot Random Samples”) par(mfrow=c(1,2)) 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) # Modify shape parameter y_rf3 <- rf(N, df1 = 20, df2 = 7) # Modify shape parameter plot(density(y_rf), # Plot default density xlim = c(- 0, 5), ylim = c(- 0, 1), main = “F Distribution in R with degrees of freedom”,lwd=3) lines(density(y_rf2), col = “coral2”,lwd=3) # Plot density with higher mean lines(density(y_rf3), col = “green3”,lwd=3) # Plot density with higher sd legend(“topright”, # Add legend to density legend = c(“Shape1 = 2, shape2=5”, “Shape1 = 10, shape2=6”, “Shape1 = 20, shape2=7”), col = c(“black”, “coral2”, “green3”),lty = 2, lwd=3) par(mfrow=c(1,1))
x_dunif <- seq(0, 100, by = 1) y_dunif <- dunif(x_dunif, min = 10, max = 50) # Apply dunif function y_punif <- punif(x_dunif, min = 10, max = 50) # Apply punif function x_qunif <- seq(0, 1, by = 0.01) # Specify x-values for qunif function y_qunif <- qunif(x_qunif, min = 10, max = 50) # Apply qunif function set.seed(13579) # Set seed for reproducibility N <- 500 # Specify sample size y_runif <- runif(N, min = 10, max = 50) # Draw N uniformly distributed values # combine plots par(mfrow=c(2,2)) plot(y_dunif, main=“Uniform Continuous Density plot”) plot(y_punif, main=“Uniform Continuous Cumulative Density plot”) plot(y_qunif, main=“Uniform Continuous Quantile plot”) plot(y_runif, main=“Uniform Continuous Scatter Plot Random Samples”) par(mfrow=c(1,2)) 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) # Modify shape parameter y_runif3 <- runif(N, min = 10, max = 70) # Modify shape parameter plot(density(y_runif), # Plot default density xlim = c(- 0, 100), ylim = c(- 0, .06), main = “F Distribution in R with degrees of freedom”,lwd=3) lines(density(y_runif2), col = “coral2”,lwd=3) # Plot density with higher mean lines(density(y_runif3), col = “green3”,lwd=3) # Plot density with higher sd legend(“topright”, # Add legend to density legend = c(“Min=10, Max=50”, “Min=10, Max=60”, “Min=10, Max=70”), col = c(“black”, “coral2”, “green3”),lty = 2, lwd=3) par(mfrow=c(1,1))
x_dbinom <- seq(0, 100, by = 1) y_dbinom <- dbinom(x_dbinom, size = 100, prob = 0.5) # Apply dbinom function y_pbinom <- pbinom(x_dbinom, size = 100, prob = 0.5) # Apply pbinom function x_qbinom <- seq(0, 1, by = 0.01) # Specify x-values for qbinom function y_qbinom <- qbinom(x_qbinom, size = 100, prob = 0.5) # Apply qbinom function set.seed(13579) # Set seed for reproducibility N <- 500 # Specify sample size y_rbinom <- rbinom(N, size = 100, prob = 0.5) # Draw N binomially distributed values y_rbinom # combine plots par(mfrow=c(2,2)) plot(y_dbinom, main=“Binomial Density plot”) plot(y_pf, main=“Gamma Cumulative Density plot”) plot(y_qf, main=“Gamma Quantile plot”) plot(y_rf, main=“Gamma Scatter Plot Random Samples”) par(mfrow=c(1,2)) 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 shape parameter y_rbinom2 <- rbinom(N,size = 100, prob = 0.7) # Modify prob parameter y_rbinom3 <- rbinom(N,size = 100, prob = 0.3) # Modify prob parameter plot(density(y_rbinom), # Plot default density xlim= c(1,100), main = “Binomial Distribution in R with degrees of freedom”,lwd=3) lines(density(y_rbinom2), col = “coral2”,lwd=3) # Plot density with higher mean lines(density(y_rbinom3), col = “green3”,lwd=3) # Plot density with higher sd legend(“topright”, # Add legend to density legend = c(“P Value = 0.5”, “P value = 0.7”, “P Value = 0.3”), col = c(“black”, “coral2”, “green3”),lty = 2, lwd=3) par(mfrow=c(1,1))
x_dpois <- seq(-5, 30, by = 1) y_dpois <- dpois(x_dpois, lambda = 10) # Apply dpois function) y_ppois <- ppois(x_dpois, lambda = 10) # Apply ppois function x_qpois <- seq(0, 1, by = 0.005) y_qpois <- qpois(x_qpois, lambda = 10) # Apply qpois function set.seed(13579) # Set seed for reproducibility N <- 500 # Specify sample size y_rpois <- rpois(N, lambda = 10) # Draw N binomially distributed values 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)) 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 shape parameter y_rpois2 <- rpois(N, lambda = 15) # Modify prob parameter y_rpois3 <- rpois(N, lambda = 20) # Modify prob parameter plot(density(y_rpois), # Plot default density xlim= c(0,60), main = “Poisson Distribution in R with lambda parameters”,lwd=3) lines(density(y_rpois2), col = “coral2”,lwd=3) # Plot density with higher mean lines(density(y_rpois3), col = “green3”,lwd=3) # Plot density with higher sd legend(“topright”, # Add legend to density legend = c(“lambda = 10”, “lambda = 15”, “;lambda = 20”), col = c(“black”, “coral2”, “green3”),lty = 2, lwd=3) par(mfrow=c(1,1))
x_dgeom <- seq(0, 20, by = 1) y_dgeom <- dgeom(x_dgeom, prob = 0.5) # Apply dgeom function) y_pgeom <- pgeom(x_dgeom, prob = 0.5) # Apply pgeom function x_qgeom <- seq(0, 1, by = 0.01) # Specify x-values for qgeom function y_qgeom <- qgeom(x_qgeom, prob = 0.5) # Apply qgeom function set.seed(13579) # Set seed for reproducibility N <- 500 # Specify sample size y_rgeom <- rgeom(N, prob = 0.5) # Draw N binomially distributed values 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)) 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 shape parameter y_rgeom2 <- rgeom(N, prob = 0.7) # Modify prob parameter y_rgeom3 <- rgeom(N, prob = 0.3) # Modify prob parameter plot(density(y_rpois), # Plot default density xlim= c(0,50), main = “Geomtric Distribution in R with Probababilities”,lwd=3) lines(density(y_rgeom2), col = “coral2”,lwd=3) # Plot density with higher mean lines(density(y_rgeom3), col = “green3”,lwd=3) # Plot density with higher sd legend(“topright”, # Add legend to density legend = c(“P value = 0.5”, “P value = 0.7”, “P value = 0.3”), col = c(“black”, “coral2”, “green3”),lty = 2, lwd=3) par(mfrow=c(1,1))
x_dnbinom <- seq(0, 100, by = 1) y_dnbinom <- dnbinom(x_dnbinom, size = 100, prob = 0.5) # Apply dnbinom function y_pnbinom <- pnbinom(x_dnbinom, size = 100, prob = 0.5) # Apply pnbinom function x_dnbinom <- seq(0, 1, by = 0.01) y_qnbinom <- qnbinom(x_dnbinom, size = 100, prob = 0.5) # Apply qnbinom function set.seed(13579) # Set seed for reproducibility N <- 500 # Specify sample size y_rnbinom <- rnbinom(N, size = 100, prob = 0.5) # Draw N binomially distributed values 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)) 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 shape parameter y_rnbinom2 <- rnbinom(N,size = 100, prob = 0.7) # Modify prob parameter y_rnbinom3 <- rnbinom(N,size = 100, prob = 0.3) # Modify prob parameter plot(density(y_rnbinom), # Plot default density xlim= c(0,300), ylim= c(0,0.07), main = “Binomial Distribution in R with degrees of freedom”,lwd=3) lines(density(y_rnbinom2), col = “coral2”,lwd=3) # Plot density with higher mean lines(density(y_rnbinom3), col = “green3”,lwd=3) # Plot density with higher sd legend(“topright”, # Add legend to density legend = c(“P Value = 0.5”, “P value = 0.7”, “P Value = 0.3”), col = c(“black”, “coral2”, “green3”),lty = 2, lwd=3) par(mfrow=c(1,1))