Question

In the R code (R studio), How to generate the gamma distribution by function?

In the R code (R studio),

How to generate the gamma distribution by function?

Homework Answers

Answer #1

we take an example for show how we generate tha gamma Distribution by function in R-Studio

R-Studio Syntax is as

# Example R Code
alpha=3
beta=12.4
avrg=alpha*beta
std.dv=sqrt(alpha*beta^2)
x=50

# Draw the Gamma Distribution
range=seq(0,avrg+5*std.dv,0.01)
y=dgamma(range,alpha,rate=1/beta)
plot(range,y,type="l",ylim=c(0,max(y)+0.01))

# Add area to the left of x
cord.a=c(0,seq(min(range),x,0.01),x)
cord.b=c(0,dgamma(seq(min(range),x,0.01),alpha,rate=1/beta),0)
polygon(cord.a,cord.b,col="blue")

# Add area to the right of x
cord.c=c(x,seq(x,max(range),0.01),b)
cord.d=c(0,dgamma(seq(x,max(range),0.01),alpha,rate=1/beta),0)
polygon(cord.c,cord.d,col=grey(0.90))

# P(X<x) Area to the left of x
pgamma(x,alpha,rate=1/beta)

# P(X>x) Area to the right of x
1-pgamma(x,alpha,rate=1/beta)

# 50th percentile median
qgamma(0.5,alpha,rate=1/beta)

And Result is as

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Use R Studio (show the code and output) Please write an R function named “outlier_detect” to...
Use R Studio (show the code and output) Please write an R function named “outlier_detect” to return or print out the outliers from a given data vector. outlier_detect = function(x){ #x: a column of numeric vector Body of code }
How to do the following in R: Write a function to generate a random sample of...
How to do the following in R: Write a function to generate a random sample of size n from the Gamma(α,1) distribution by the acceptance-rejection method. Generate a random sample of size 1000 from the Gamma(3,1) distribution. (Hint: you may use g(x) ∼ Exp(λ = 1/α) as your proposal distribution, where λ is the rate parameter. Figure out the appropriate constant c).
How to do the following in R: Write a function to generate a random sample of...
How to do the following in R: Write a function to generate a random sample of size n from the Gamma(α,1) distribution by the acceptance-rejection method. Generate a random sample of size 1000 from the Gamma(3,1) distribution. (Hint: you may use g(x) ∼ Exp(λ = 1/α) as your proposal distribution, where λ is the rate parameter. Figure out the appropriate constant c).
Use R to code a function to generate a random sample of size n from the...
Use R to code a function to generate a random sample of size n from the Beta(a, b) distribution by the acceptance-rejection method. (1) Generate a random sample of size 3000 from the Beta(4,3) distribution. (2) Graph the histogram of the sample with the theoretical Beta(4,3) density superimposed. Answer the above questions by showing the R codes and results.
How to do the following in R: Write a function to generate a random sample of...
How to do the following in R: Write a function to generate a random sample of size n from the Beta(a,b) distribution by the acceptance-rejection method. Generate a random sample of size 1000 from the Beta(3,2) distribution.
In R- Studio : Write a function that takes as an input a positive integer and...
In R- Studio : Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Write a recursive function, do not use any of the loop commands in your code.
The following question can be answered in R code (using R-Studio or a program of your...
The following question can be answered in R code (using R-Studio or a program of your choice). Load the “star” data from the “faraway” package, and model “temp” using “light”. One may also suspect that the residuals (use all the data) follow a t distribution instead of normal. Using the same logic that we produced the QQ plot for comparing to the normal distribution, produce a QQ plot for comparing to a t distribution. You need to decide the degrees...
How can I convert this apply function in R studio apply(trees, 1, function(x) tree_s3(x[1],x[2],x[3])) into a...
How can I convert this apply function in R studio apply(trees, 1, function(x) tree_s3(x[1],x[2],x[3])) into a for loop?
Using R Studio: Include R Code: A new drug therapy is tested. Of the 50 patients...
Using R Studio: Include R Code: A new drug therapy is tested. Of the 50 patients in the study, 40 had no recurrence of their illness after 18 months. With no drug therapy, the expected percentage of no recurrence would have been 72%. Does the data support the hypothesis that the non-recurrence percentage has increased with this therapy? What is the p-value?
How to create a scatter plot on R studio?
How to create a scatter plot on R studio?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT