Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Programming Normal Distribution

enter image description here

I am trying to create this plot. When I tried the code below plot is not distributed normally.

x <- seq(60,140,20)
y <- dnorm(x,0,1)
plot(x,y,type="l",xlab = "x",ylab = "f(x)",main = "The total shades area is equal to 0.05")
x<-seq(60,80)
y<-dnorm(x,0,1)
polygon(c(60,x,80),c(0,y,0),col="red")
x<-seq(120,140,length=100)
y<-dnorm(x,0,1)
polygon(c(120,x,140),c(0,y,0),col="red")
like image 562
tylerdurdenX Avatar asked Feb 11 '26 01:02

tylerdurdenX


1 Answers

It looks like the biggest issue with your plot is that, based on your image, you want to graph a normal distribution with mean 100 and standard deviation 10, but anytime you call dnorm, you're using a mean of 0 and a standard deviation of 1.

A secondary issue is that when you're defining the first sequence x, you have the by argument equal to 20, which means you're only using 60, 80, 100, 120, and 140 as the x coordinates for your normal curve. Try using something smaller--like 1--instead.

The code below should return the graph you're looking for.

x <- seq(60,140,1)
y <- dnorm(x,100,10)
plot(x,y,type="l",xlab = "x",ylab = "f(x)",
     main = "The total shaded area is equal to 0.05")
x<-seq(60,80)
y<-dnorm(x,100,10)
polygon(c(60,x,80),c(0,y,0),col="red")
x<-seq(120,140,length=100)
y<-dnorm(x,100,10)
polygon(c(120,x,140),c(0,y,0),col="red")
like image 75
Lynn L Avatar answered Feb 13 '26 14:02

Lynn L



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!