PMF, CDF and Quantile function of Bernoulli's Distribution
PMF:
library(Rlab)
# Specify x-values for the dbern() function
x <- seq(0, 10, by = 1)
# Compute the corresponding Bernoulli PDF
y <- dbern(x, prob = 0.5)
cat("The required PMF of X=",x,"are",y)
# Plot the PMF
plot(x, y, type = "o", main = "PMF of Bernoulli Distribution")
Output:
> cat("The required PMF of X=",x,"are",y)
The required PMF of X= 0 1 2 3 4 5 6 7 8 9 10 are 0.5 0.5 0 0 0 0 0 0 0 0 0
2. CDF:
# Specify x-values for the pbern() function
x <- seq(0, 10, by = 1)
# Compute the corresponding Bernoulli CDF
y <- pbern(x, prob = 0.7)
y
# Plot the CDF
plot(y, type = "o", main = "CDF of Bernoulli Distribution")
Output:
> y
[1] 0.3 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
3. Quantile Function:
# Specify probabilities (values between 0 and 1)
p_values <- seq(0, 1, by = 0.1)
# Compute the corresponding quantile function values
Quantiles <- qbern(p_values, prob = 0.7)
cat("The required quantiles are",Quantiles)
# Plot the quantile function
plot(Quantiles, type = "o", main = "Quantile Function of Bernoulli Distribution")
Output:
> cat("The required quantiles are",Quantiles)
The required quantiles are 0 0 0 0 1 1 1 1 1 1 1
PMF, CDF and Quantile function of Binomial Distribution
PMF:
# Specify the number of trials (size) and the probability of success
n <- 10
p_success <- 0.2
# Calculate the PMF for x = 1, 2, ..., 10
x_values <- 1:10
pmf_values <- dbinom(x_values, size = n, prob = p_success)
cat("The required PMF values of X=",x_values,"are ",pmf_values)
# Plot the PMF
plot(x_values, pmf_values, type = "o", main = "PMF of Binomial Distribution")
Output:
> cat("The required PMF values of X=",x_values,"are ",pmf_values)
The required PMF values of X= 1 2 3 4 5 6 7 8 9 10 are 0.2684355 0.3019899 0.2013266 0.08808038 0.02642412 0.005505024 0.000786432 7.3728e-05 4.096e-06 1.024e-07
2. CDF:
# Specify the number of trials (size) and the probability of success
n <- 10
p_success <- 0.2
x_values <- 1:10
# Calculate the CDF for x = 1, 2, ..., 10
cdf_values <- pbinom(x_values, size = n, prob = p_success)
cat("The required CDF values of X=",x_values,"are ",cdf_values)
# Plot the CDF
plot(x_values, cdf_values, type = "o", main = "CDF of Binomial Distribution")
Output:
> cat("The required CDF values of X=",x_values,"are ",cdf_values)
The required CDF values of X= 1 2 3 4 5 6 7 8 9 10 are 0.3758096 0.6777995 0.8791261 0.9672065 0.9936306 0.9991356 0.9999221 0.9999958 0.9999999 1
3. Quantile Function:
# Specify probabilities (values between 0 and 1)
n <- 10
p_values <- seq(0.1, 0.9, by = 0.1)
# Compute the corresponding quantile function values
quantiles <- qbinom(p_values, size = n, prob = p_success)
# Plot the quantile function
cat("The required quantiles are",quantiles)
# Plot the quantile function
plot(p_values, quantiles, type = "o", main = "Quantile Function of Binomial Distribution")
Output:
> cat("The required quantiles are",quantiles)
The required quantiles are 0 1 1 2 2 2 3 3 4
PMF, CDF and Quantile function of Poisson Distribution
PMF:
x<-seq(0,10,1)
l<-5
pmf_pois<-dpois(x, lambda = l)
cat("The required PMF of X=",x,"are",pmf_pois)
plot(x,pmf_pois,type = "o",xlab = "X",ylab = "pmf_pois",main = "PMF of Poisson Distribution")
Output:
> cat("The required PMF of X=",x,"are",pmf_pois)
The required PMF of X= 0 1 2 3 4 5 6 7 8 9 10 are 0.006737947 0.03368973 0.08422434 0.1403739 0.1754674 0.1754674 0.1462228 0.1044449 0.06527804 0.03626558 0.01813279
2. CDF:
x<-seq(0,20,1)
l<-5
cdf_pois<-ppois(x, lambda = l)
cat("The required CDF's are",pmf_pois)
plot(x,cdf_pois,type = "o",xlab = "X",ylab = "pmf_pois",main = "CDF of Poisson Distribution")
Output:
> cat("The required CDF's are",pmf_pois)
The required CDF's are 0.006737947 0.03368973 0.08422434 0.1403739 0.1754674 0.1754674 0.1462228 0.1044449 0.06527804 0.03626558 0.01813279
3. Quantiles:
x<-seq(0,20,1)
l<-5
pmf_pois<-ppois(x, lambda = l)
quan_pois<-qpois(pmf_pois, lambda = l)
cat("The required quantiles are",quan_pois)
plot(pmf_pois,quan_pois,type = "o",xlab = "pmf_pois",ylab = "quan_pois",main = "Quantile function of Poisson Distribution")
Output:
> cat("The required quantiles are",quan_pois)
The required quantiles are 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
PDF, CDF and Quantile function of Normal Distribution
PDF:
n<-50
mean<-0
sd<-1
x<-rnorm(n,mean,sd)
pdf<-dnorm(x,mean,sd)
cat("The required PDF of X=",round(x,4),"are",round(pdf,4))
plot(x,round(pdf,4),xlab="X",ylab="pdf",xlim=c(-3,3), main = "PDF of Normal Distribution")
Output:
> cat("The required PDF of X=",round(x,4),"are",round(pdf,4))
The required PDF of X= 1.4737 -0.1439 -0.3712 -0.025 1.1993 -0.3584 0.1427 -0.0397 -0.4474 -1.3856 0.1151 1.4584 -0.3049 0.1994 -0.5889 -0.6316 0.5959 2.5083 -0.2943 0.9237 -0.4291 0.5043 0.7995 -0.0297 -0.3926 0.4694 -1.8162 -0.2475 -0.9988 0.8383 -0.222 1.1932 -0.6461 0.6546 -0.512 1.8595 -0.785 1.0111 -0.2824 -2.4061 0.2834 -0.6335 -0.5443 2.5264 0.8091 1.0712 0.6187 0.8533 0.2632 -0.2894 are 0.1347 0.3948 0.3724 0.3988 0.1943 0.3741 0.3949 0.3986 0.3609 0.1528 0.3963 0.1377 0.3808 0.3911 0.3354 0.3268 0.334 0.0172 0.382 0.2604 0.3639 0.3513 0.2898 0.3988 0.3693 0.3573 0.0767 0.3869 0.2423 0.2807 0.3892 0.1958 0.3238 0.322 0.3499 0.0708 0.2932 0.2393 0.3834 0.0221 0.3832 0.3264 0.344 0.0164 0.2876 0.2248 0.3295 0.2772 0.3854 0.3826
2. CDF: