Using R programming language, complete the following.
1. Generate the bivariate normal sample of size 100 with
parameters
a. marginal mean of X equal to 1,
b. marginal mean of Y equal to 2,
c. marginal variance of X equal to 3,
d. marginal variance of Y equal to 4,
e. correlation between X and Y equal to -1/2.
You can use the function mvrnorm(), first installing its package by
the code
if (! require ("MASS")) install.packages("MASS"); library
("MASS")
2. Produce scatter plot.
3. Create histogram of a marginal distribution of X. You can use
the function hist()
4. Create qq plot (probability plot) of a marginal distribution of
X vs normal and comment on it. You can use the function
qqnorm().
5. Compute sample means and sample variances of X and Y marginal
distributions, and sample correlation between X and Y. You can use
the functions mean(), var(), cor().
3.
4.
As from QQ plot we can see that the points follow linear line so we can say that X and Y come from normal distribution.
(5) [1] 1.245655 [1] 2.053158 > var(X);var(Y) [1] 3.048119 [1] 3.305575 > cor(X,Y) [1] -0.09814289
The code that we used are below.
library(MASS)
mu=c(1,2)
Sigma=matrix(c(3,-.5,-.5,4),2,2)
xx=mvrnorm(n = 100, mu, Sigma, tol = 1e-6, empirical = FALSE,
EISPACK = FALSE)
X=xx[,1];Y=xx[,2]
plot(x,xlab = "X",ylab = "Y")
hist(X)
hist(Y)
qqnorm(X,main = "Normal QQ Plot of X")
qqnorm(Y,main = "Normal QQ Plot of Y")
mean(X);mean(Y)
var(X);var(Y)
cor(X,Y)
Get Answers For Free
Most questions answered within 1 hours.