In: Statistics and Probability
Write the R code
First, generate 1000 observations from a binomial distribution with n=30 and p=0.2 Use the 1000 observations you generated:
a) Generate poisson, binomial, negative binomial Diagnostic Distribution Plots using distplot.
b) Generate a histogram and overlay a kernel estimator of the density
(You can use: binom <- rbinom(n=1000,size=30, prob=0.2))
Generate 1000 random observations of binomial distribution with n=30 and p=0.2
>obs<-rbinom(1000,30,0.2)
(a) Using above observations, generate Diagnostic Distribution Plot
install.packages("vcd")
library("vcd")
> distplot(obs, type="poisson")
> distplot(obs, type="binomial")
> distplot(obs, type="nbinomial")
> #(b) Histogram and overlay Kernel estimator of the
density
> x <-obs
> h<-hist(x, breaks=10, col="red", xlab=" ", main="Histogram
with Normal Curve")
> xfit<-seq(min(x),max(x),length=40)
> yfit<-dnorm(xfit,mean=mean(x),sd=sd(x))
> yfit <- yfit*diff(h$mids[1:2])*length(x)
> lines(xfit, yfit, col="blue", lwd=2)