Search code examples
rdnsbeta-distribution

domain using plot function in r


I start saying that i am really new to R, hence this could be a very simple problem.

I want to do a monte carlo simulation with a beta distribution. The case is that i have a website, which will receive from 0 to 10 visualisations each day for one year, and i want to simulate this.

The first step in my dissertation is to produce a diagram showing the shape of the beta distribution.

To do so, i do

x=rbeta(365,1,4,ncp=0)
y=dbeta(x,1,4)
plot(10*x,y,type="l")

which gives to me an ugly diagram like this: first diagram

then i tried to do

x=rbeta(365,1,4,ncp=0)
plot(density(10*x))

in this case i obtain the right diagram which has this flaw: it exceedes the domain [0,10] on the 0 side:

second diagram

can anyone help me? thank you for your help in advance!

Answer part: by using plot(density(10*x), xlim = c(0, 10)) i obtain answer 1 which again has the ptoblem with the offset of the domain and not only, it seems like if the function was moved to the right, since i expect that given x1


Solution

  • Do you literally just want a plot of the Beta distribution with parameters 1, 4?:

    # Points over which we will evaluate Beta PDF
    x <- seq(0, 1, 0.05)
    
    # PDF values
    y <- dbeta(x, 1, 4, ncp=0)
    
    plot(x*10, y, type="l")
    

    enter image description here

    If you really want something simulated you could also do a histogram like this:

    hist(rbeta(2000, 1, 4, ncp=0), breaks=25)
    

    enter image description here