Question

In: Computer Science

Codes for this R-Project please! In this projects we will draw plots for different discrete probability...

Codes for this R-Project please!


In this projects we will draw plots for different discrete probability distributions that we have studied in class.

# 1. Binomial distribution.
We will plot the density function for the binomial distribution Bin(n, p).
Note:
1) The values for this random variable are 0, 1, 2, ..., n.
2) The density plot will have a bar of height P(X=k), at the point 'k' on the x-axis.
3) In the plot include a vertical line at the expected value of Bin(n,p).

Write a function plot_binom, that takes input values: n and p, and returns the density plot of Bin(n,p).


```{r}
# plot_binom <- function(n,p){
# x <- 0:n
# bin <- dbinom( _____ ) # input appropriate parameters
# mu_X <- ____ #input appropriate value for expected value
# plot(x, bin, type = "h", lwd = 5,
# main = paste("Binom density: n = ", n ,"and p = ", p),
# xlab = "x", ylab = "P(X=x)")
# abline(v = mu_X, col = 'red', lwd = 4)
# }
```
Fix n = 40. Compute plots for the following values of p: 0.05, 0.1, 0.4, 0.6, 0.9, 0.95.
Use the command "par(mfrow=c(3,2))" to have all the plots on the same frame.

```{r}
# n <- 40
# prob_vals <- c(_______) #input appropriate values for probability
# par(mfrow=c(3,2))
# for (p in prob_vals){
# plot_binom(____) #input the appropriate values
#}
```

Write at least two observations that you can note from these plots. Consider skewness and symmetry.

Solutions

Expert Solution

Work Screenshot :

Plotting Screen shot:

Code

plot_binom <- function(n,p){
x <- 0:n
bin <- dbinom(x,n,p )
mu_X <- 15
plot(x, bin, type = "h", lwd = 5,
main = paste("Binom density: n = ", n ,"and p = ", p),
xlab = "x", ylab = "P(X=x)")
abline(v = mu_X, col = 'red', lwd = 4)
}

n <- 40
prob_vals <- c(0.05, 0.1, 0.4, 0.6, 0.9, 0.95)
par(mfrow=c(3,2))
for (p in prob_vals){
plot_binom(n,p)
}

For this code I have set expected value to be 30

After plotting the graphs , It is observed that

1. The distribution is symmetric around the mean value, when p value is nearer to 0.5.

2. When p > 0.5, the distribution is skewed to the left.

3. When p < 0.5, the distribution is skewed to the right.

I hope , I have completed your assignment and also provided the observations from the plotting in terms of symmetry and skewness.

If further customization needed , please specify.?

Thank You?


Related Solutions

Need R codes to compile and plots , no hand written. Step-1: Type the data in...
Need R codes to compile and plots , no hand written. Step-1: Type the data in R Step-2: Perform Least-Squares regression Step-3: Make a normal Probability Plot using rstudent residuals Step-4: Plotting residuals versus predicted response yhat Step-5: Plotting Residuals versus each regressor. Step-6: Partial regression plots of residuals vs. regressors Step-7: Partial regression plots of residuals vs. regressors data:  (p.555 y, x1 and x5). y <- c(271.8, 264,238.8,230.7,251.6,257.9,263.9,266.5,229.1,239.3,258, 257.6,267.3,267,259.6,240.4,227.2,196,278.7,272.3,267.4,254.5,224.7, 181.5,227.5,253.6,263,265.8,263.8) x1 <- c(783.35, 748.45,684.45,827.8,860.45,875.15,909.45,905.55,756,769.35,793.5,801.65,819.65,808.55,774.95,711.85,694.85,638.1,774.55,757.9,753.35,704.7, 666.8,568.55,653.1,704.05,709.6,726.9,697.15) x5 <- c(13.2, 14.11,15.68,10.53,11,11.31,11.96,12.58,10.66,10.85,11.41,11.91,12.85,13.58,14.21,15.56,15.83,16.41,13.1,13.63,14.51,15.38, 16.1,16.73,10.58,11.28,11.91,12.65,14.06)
discrete probability distributions There are 37 different processors on the motherboard of a controller. 6 of...
discrete probability distributions There are 37 different processors on the motherboard of a controller. 6 of the processors are faulty. It is known that there are one or more faults on the motherboard. In an attempt to locate the error, 7 random processors are selected for testing. tasks a) Determine the expected number of defective processors. Round your answer to 2 decimal places. b) Determine the variance of the number of defective processors. Round your answer to 4 decimal places....
Explain why the probability of a number X is thought of as different under discrete versus...
Explain why the probability of a number X is thought of as different under discrete versus continuous distributions.
The binomial and Poisson distributions are two different discrete probability distributions. Explain the differences between the...
The binomial and Poisson distributions are two different discrete probability distributions. Explain the differences between the distributions and provide an example of how they could be used in your industry or field of study. In replies to peers, discuss additional differences that have not already been identified and provide additional examples of how the distributions can be used.
The binomial and Poisson distributions are two different discrete probability distributions. Explain the differences between the...
The binomial and Poisson distributions are two different discrete probability distributions. Explain the differences between the distributions and provide an example of how they could be used in your industry or field of study.
use r programming, details on the codes please. Consider an urn with 10 balls inside, 7...
use r programming, details on the codes please. Consider an urn with 10 balls inside, 7 of which are red and 3 of which are green. Select 3 balls successively from the urn. Let A = {1 st ball is red}, B = {2 nd ball is red}, and C = {3 rd ball is red}. Then P(all 3 balls are red) = P(A ∩ B ∩ C)      a) Calculate the Probability with R? (1)      b) Also, what is the...
Please write down all formulas needed to solve and explanation of each formula for Probability, Discrete...
Please write down all formulas needed to solve and explanation of each formula for Probability, Discrete random variables and their distribution, and continuous distribution. ie from permutation and combination to bayes theorem to binomial. reference to probabilty and statistics for computer scientists 2nd edition. thanks
Please Provide R code as well Use R to find probability (p-value). Find probability P(X>12.3), where...
Please Provide R code as well Use R to find probability (p-value). Find probability P(X>12.3), where X follows F-distribution with degree of freedom in numerator 4 and degree of freedom in numerator 10.
Risk in capital projects is the probability that a project will earn less than expected. Make...
Risk in capital projects is the probability that a project will earn less than expected. Make up and describe one hypothetical project in each of the replacement, expansions and new venture categories. List a few ways that each might go wrong and cause the cash flow to be less favorable than expected. Can you think of situations in which projects could result in losses? Could the losses exceed the initial investment?
Please answer all questions. Draw a multi-cycle processor for lw $t0,20($t1). what if we have different...
Please answer all questions. Draw a multi-cycle processor for lw $t0,20($t1). what if we have different numbers like $s0 instead of $t1, does anything changes? Does place of $t1, $t0 change in sw or any other instruction for multi-cycle processor,
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT