using the statistical software R and R Studio d ASSIGNMENT 1. Review the R Demo
ID: 3156004 • Letter: U
Question
using the statistical software R and R Studio d ASSIGNMENT 1. Review the R Demo and go through all of the commands on your own (you do not need to submit this part). 2. Let X B(10,1/2). Use R to: (a) Generate 10 independent random variables with the distribution of X and store them in a vector called B1. Repeat for 100 random variables, and 1000, and store in vectors called B2, B3, and B4, respectively (b) Find the mean of each vector in part (a), and store this as B1 mean, B2_mean, etc. (c) Find the standard deviation of each vector in part (a), and store this as B1sd. B2_sd, etc (d) Find the maximum and minimum value for each of your vectors from part (a) and store as B1 max, B1 min, etc (e) Create a frequency table for each vector from part (a) and store these tables as B1_Freq Table, etc. (f) Create a histogram with frequencies for each vector in part (a). The histogram should have a title, x- and y-axis labels, and each bar should include only one possible value of the random variable (for example, a single bar should not count the frequency of both X-0 and X = 1). Name each histogran BI-Freq,_Aist. etc. (g) Create a histogram with probabilities for each vector in part (a). The histogram should have a title, x- and y-axis labels, and each bar should include only one possible value of the random variable. Name each histogram B1_Prob Hist, etc. (h) Over your probability histogram, draw a normal curve with the appropriate mean and standard deviation from parts (b) and (c). Name each curve B1 Normal Curve. etc. 3. Let ~ B(10, p), where p is of your choice (do not use p = 0.1/21). Repeat parts (a)-(h). Use the same naming system for all objects, but replace the letter B with the letter C. 4. If your last name begins with a letter from A-H. let Z~geo(1/2). If your last name begins with a letter from I-P, let Z ~Poisson(2) If your last name begins with a letter from Q-Z, let Z~ exp(2). Repeat parts (a)-h), using the same naming system, but replace the letter B with the letter D. For your histograms, you should choose an appropriate number of bars in each case, so that the graphs accurately reflect the vectors that you have generated 5. Repeat #4 with a different value for the parameter, of your choice. Use the same naming system, but with the letter E.Explanation / Answer
2) Use the following commands:-
a)
> B1=rbinom(10,10,1/2)
> B2=rbinom(100,10,1/2)
> B3=rbinom(1000,10,1/2)
b)
> B1_mean=mean(B1)
> B2_mean=mean(B2)
> B3_mean=mean(B3)
c)
> B1_sd=sd(B1)
> B2_sd=sd(B2)
> B3_sd=sd(B3)
d)
> B1_max=max(B1)
> B1_min=min(B1)
> B2_max=max(B2)
> B2_min=min(B2)
> B3_max=max(B3)
> B3_min=min(B3)
e)
> B1_Freq_Table=table(B1)
> B2_Freq_Table=table(B2)
> B3_Freq_Table=table(B3)
f)
> B1_Freq_Hist=hist(B1,main="Histogram of B1",xlab="observations",ylab="frequency")
> B2_Freq_Hist=hist(B2,main="Histogram of B2",xlab="observations",ylab="frequency")
> B3_Freq_Hist=hist(B3,main="Histogram of B3",xlab="observations",ylab="frequency")
g)
> B1_Prob_Hist=hist(B1,main="Histogram of B1",xlab="observations",ylab="frequency",freq=F)
> B2_Prob_Hist=hist(B2,main="Histogram of B2",xlab="observations",ylab="frequency",freq=F)
> B3_Prob_Hist=hist(B3,main="Histogram of B3",xlab="observations",ylab="frequency",freq=F)
h) In order to draw a Normal Curve over all the probability histograms, first open the corresponding probability histogram in the plot section and then run the following command:-
Open the probability histogram of B1 and then type
> B1_Normal_Curve=curve(dnorm(x,mean=B1_mean,sd=B1_sd),add=T)
Open the probability histogram of B2 and then type
> B2_Normal_Curve=curve(dnorm(x,mean=B2_mean,sd=B2_sd),add=T)
Open the probability histogram of B3 and then type
> B3_Normal_Curve=curve(dnorm(x,mean=B3_mean,sd=B3_sd),add=T)
For the problems 3,4 & 5 repeat the same procedure showed in 2 and just change the names and parameters according to the questions.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.