In: Computer Science
R programing question
Generate two vectors x and y of length B=10000 so that each of the entries is independent, with Xi ~ N(0,1) and Yi ~ N(1,4) for i=1,2,...,10000
ANSWER:
Given that,
length B=10000 // that each of the entries is independent, with Xi ~ N(0,1) and Yi ~ N(1,4) for i=1,2,...,10000
R programing,
B=10000
x=rnorm(B)
y=rnorm(B,1,4)
hist(x,main=“Histogram of x”)
hist(y,xlim=c(-15,15),main="Histogram of y")
Explanation of the R programing:----
Ø Here B is sample size that is 10000
Ø X=rnorm(B) means x is a vector of sample size B from normal distribution with mean=0 and variance=1
Ø y=rnorm(B,1,4) means y is a vector of sample size B from normal distribution with mean=1 and variance=4
Ø hist(x,main=“Histogram of x”) is histogram of x
Ø hist(y,xlim=c(-15,15),main="Histogram of y") is histogram of y
Generate two vectors x and y:
> B=10000
> x=rnorm(B)
> y=rnorm(B,1,4)
> hist(x,main=“Histogram of x”)
> hist(y,xlim=c(-15,15),main="Histogram of y")
Here Histogram of x is centered at zero whereas Histogram of y is centered at 1.
Spread of histogram of y is greater than that of x because for x variance is 1 and that of y is 4 therefore as variance increases spread increases.