Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Generate 200 random observations from the 3-dimensional multivariate normal dist

ID: 3276165 • Letter: G

Question

Generate 200 random observations from the 3-dimensional multivariate normal distribution having mean vector µ = (0, 1, 2) and covariance matrix

=

using the Choleski factorization method. Use the R pairs plot to graph an array of scatter plots for each pair of variables. For each pair of variables, 96 Statistical Computing with R (visually) check that the location and correlation approximately agree with the theoretical parameters of the corresponding bivariate normal distribution.

1.0 -0.5 0.5 -0.5 1.0 -0.5 0.5 -0.5 1

Explanation / Answer

a=matrix(c(1,-.5,.5,-.5,1,-.5,.5,-.5,1),3,3)

chol(a)

library(MASS)

sim=mvrnorm(200,c(0,0,0),a)

inv=solve(a)

inv

fin=matrix(c(rep(0,600)),200,3)

for(i in 1:200)

{

fin[i,]=inv%*%(sim[i,])+c(0,1,2)

}

fin

#fin gives simulated values from the required muktivariate normal distribution

m=rep(0,3)

for(i in 1:3)

{

m[i]=mean(fin[,i])

}

m

var(cbind(fin[,1:2]))

var(cbind(fin[,2:3]))

var(cbind(fin[,1],fin[,3]))

OUTPUT:

> a=matrix(c(1,-.5,.5,-.5,1,-.5,.5,-.5,1),3,3)

> chol(a)

     [,1]       [,2]       [,3]

[1,]    1 -0.5000000 0.5000000

[2,]    0 0.8660254 -0.2886751

[3,]    0 0.0000000 0.8164966

> library(MASS)

> sim=mvrnorm(200,c(0,0,0),a)

> inv=solve(a)

> inv

     [,1] [,2] [,3]

[1,] 1.5 0.5 -0.5

[2,] 0.5 1.5 0.5

[3,] -0.5 0.5 1.5

> fin=matrix(c(rep(0,600)),200,3)

> for(i in 1:200)

+ {

+ fin[i,]=inv%*%(sim[i,])+c(0,1,2)

+ }

> fin

               [,1]        [,2]        [,3]

[1,] -0.623956757 0.50514208 1.37760399

[2,] -0.167635624 1.72504797 1.90768418

[3,] 1.993734661 0.53047809 3.03267829

[4,] -0.630488179 2.45258703 1.19982067

[5,] 0.598269971 2.94607029 3.64387058

[6,] -0.622801137 1.68712912 2.94484683

[7,] 0.884584378 1.92770524 1.13780734

[8,] -0.758742719 0.17700156 2.29815135

[9,] -1.140797332 0.42779202 1.44969890

[10,] -0.224241872 1.87776895 1.56125147

[11,] 0.452714081 0.83660468 2.85139807

[12,] -1.646939546 0.35178381 1.99346900

[13,] 1.445202355 2.53897680 3.02709808

[14,] 0.636635964 1.94631069 3.24391554

[15,] -1.930883132 0.49563518 1.78811095

[16,] -1.183756666 -1.31509419 0.27030722

[17,] -0.693052752 2.14813145 2.69976939

[18,] 0.095275974 0.90604205 3.18051912

[19,] -0.322108826 0.07595851 1.58233027

[20,] -0.570078764 -0.38165954 2.03309613

[21,] -0.633800199 1.24617843 2.19411994

[22,] -0.096817584 1.48470626 1.40523165

[23,] 0.618373996 2.33502761 2.91112499

[24,] -1.530052642 1.45444663 3.40919268

[25,] -0.167945914 1.42275143 3.94251389

[26,] -0.543176206 1.20970164 0.90558117

[27,] 0.708545252 1.08531851 2.15957082

[28,] -0.477515370 0.62181477 2.21527622

[29,] -0.695239052 2.25767634 1.38486613

[30,] -1.342374879 -0.74872725 1.10049466

[31,] 0.700366483 4.04508071 3.22842971

[32,] -0.467094925 0.77145490 1.52895589

[33,] 0.522693170 2.33572966 2.00855036

[34,] -1.558542650 0.03035019 2.38167829

[35,] 0.859421506 0.33422816 1.77332960

[36,] -0.256724329 4.49074623 2.37931634

[37,] 0.878644607 3.81180711 3.57762239

[38,] 0.356742938 0.37348433 1.44568217

[39,] 0.072884542 3.01709726 4.07755087

[40,] -1.273223327 1.40487966 4.31509441

[41,] 1.052195618 2.47584388 -0.04644935

[42,] -0.642861005 -0.28825063 2.50302416

[43,] 0.541145944 3.57412229 2.05078217

[44,] 0.283187459 -0.85809702 1.44958629

[45,] -0.288222829 0.79906730 3.19561602

[46,] -1.001344154 -0.27762362 0.91358629

[47,] 1.053395843 0.20734450 3.52097485

[48,] -1.572104868 0.54943232 0.48047220

[49,] 0.080342511 0.65430291 1.98942663

[50,] -1.929291570 -0.70013819 0.18693936

[51,] 1.139185717 0.21801456 1.10988611

[52,] -0.372056612 -0.26969031 0.52920044

[53,] -1.002193231 1.91223229 3.93162271

[54,] 0.957463260 0.91132100 4.05250002

[55,] -1.573443433 0.97575125 1.71384562

[56,] -0.987061011 0.22064068 2.17314210

[57,] -1.031167981 -0.81181454 2.02330908

[58,] 0.713961072 2.32920160 0.55036079

[59,] 0.224132276 3.80041568 5.04762889

[60,] 1.398190187 -0.05755033 1.40672709

[61,] 0.162083396 -1.25965003 2.39210836

[62,] 0.695517106 3.90319266 1.82804021

[63,] -1.106672800 0.14518276 3.43804291

[64,] 0.221051007 -0.15682623 0.94537375

[65,] 0.314705133 2.61769464 4.19716113

[66,] -1.567802168 0.98161672 4.47486163

[67,] -1.306279196 2.31299595 3.41948663

[68,] 1.205809686 1.69415896 1.75969000

[69,] -0.319766296 1.11480800 1.69846810

[70,] -0.891263234 2.23141531 2.86770226

[71,] 0.259816194 0.91521023 0.80360101

[72,] 0.176035166 1.36117474 4.42802035

[73,] 1.737185577 0.45274663 -1.36087895

[74,] 1.153052503 2.89540978 1.42088420

[75,] -2.199708476 1.85137904 4.63169115

[76,] -0.499932909 0.91213665 1.98396456

[77,] 1.079188814 1.03322159 0.78480606

[78,] 1.819573740 0.75220071 2.06235478

[79,] -1.244477750 0.57062997 3.92750428

[80,] 0.497893067 -1.05824163 0.32249468

[81,] 2.176308322 1.91509459 0.81357922

[82,] -2.190398297 1.01680983 1.72291802

[83,] 0.865682231 1.80750963 0.13965361

[84,] -1.364233063 -1.17284860 2.76143151

[85,] -1.219977559 -1.57275138 0.88266540

[86,] 0.240890201 0.60603235 3.06938186

[87,] 1.247765972 2.57748745 1.82170874

[88,] 0.330868247 2.58829301 2.54454584

[89,] 0.240400326 0.85351819 0.80085529

[90,] -2.188153701 1.83758017 3.94639101

[91,] 0.662263326 0.83085636 2.89078672

[92,] -0.236725089 0.24910239 0.48095285

[93,] -0.829641889 1.68199108 2.12816048

[94,] -0.907495140 -1.53364600 0.58388732

[95,] 0.711829733 0.61229247 1.39954572

[96,] 0.627135791 3.44916769 2.76510212

[97,] 2.473029284 0.41563352 0.77865548

[98,] -0.453179866 -0.13506984 0.80878329

[99,] 1.239654665 1.87916253 -0.15262535

[100,] 0.795557180 -0.13150917 1.05567308

[101,] 0.965107502 -0.18327461 0.77555431

[102,] -4.018981035 -0.24353633 2.01800558

[103,] 1.329669949 2.82526206 2.77725557

[104,] 0.893922535 0.37677531 0.81527641

[105,] 0.157884523 0.61447187 1.88556330

[106,] 0.136357079 -1.14523503 -1.15446423

[107,] -1.743337522 -0.17682973 1.69518223

[108,] -0.225866451 -0.24539347 0.25800178

[109,] 0.625122840 0.56918070 1.52702313

[110,] 0.107272656 -0.79703299 0.70956688

[111,] 1.030401756 1.07819985 2.74573784

[112,] -0.234860813 1.49438649 0.68984651

[113,] 0.688380150 4.23092113 3.70106495

[114,] -1.277624862 0.05406976 3.43104808

[115,] -0.727047391 1.07376004 2.13862707

[116,] -1.091312900 0.48951642 1.42175678

[117,] 0.595053771 3.03512467 2.73903247

[118,] -0.888063354 0.54642956 2.42429816

[119,] -0.104747510 1.35509147 1.78688133

[120,] -0.904546379 1.36828753 1.84268203

[121,] -0.536761641 -0.25024960 2.36339485

[122,] 1.199677139 0.28136305 -0.77944235

[123,] 0.269859118 1.31873278 3.47179772

[124,] 0.105249721 0.72689660 0.49306434

[125,] 1.153385031 1.32177855 0.81038827

[126,] 3.611227008 1.36492895 0.56867008

[127,] -0.657077520 -0.46037036 1.02224174

[128,] 1.263587260 -0.05738775 2.87190183

[129,] -1.163150430 -0.50116371 0.62819345

[130,] -1.384297579 -1.19156216 -0.03101212

[131,] -0.423406585 2.05501994 2.48065223

[132,] -1.717866758 -0.56340589 1.33437479

[133,] -0.434391841 0.72801524 2.15425676

[134,] 1.553222419 0.55732977 0.78255285

[135,] 0.375074507 1.75690231 1.75568623

[136,] 2.942454684 2.02110103 1.70369408

[137,] -1.116208916 -0.36491553 3.05373288

[138,] 0.272529331 -0.01823784 1.07140619

[139,] -0.495680184 1.23197432 2.00063869

[140,] 0.711395000 2.06697666 1.81218932

[141,] -0.170017993 -0.41848592 0.40802757

[142,] -0.529487087 0.88390551 3.60928055

[143,] -1.638413247 -0.38038418 1.04165134

[144,] -2.421616325 1.14071279 4.51828964

[145,] -1.009703654 1.55519808 3.21440231

[146,] 1.322934023 0.97118544 -0.20121820

[147,] 1.796991533 2.34375582 0.85941002

[148,] -1.138300809 -0.43116917 2.44312633

[149,] 1.456810814 2.91559219 0.50760623

[150,] -1.316725822 2.62298192 3.69988644

[151,] 0.547369212 0.86433237 1.85454531

[152,] -0.378212309 0.64953528 2.88615417

[153,] -2.255802610 -0.06504739 3.06405674

[154,] 1.440948297 0.51450978 1.07721279

[155,] 0.570008414 0.79777506 0.52589307

[156,] -1.000261718 0.18780702 1.27047529

[157,] -0.607782069 1.06019006 2.31645818

[158,] 0.078674965 0.72366175 3.99111334

[159,] 0.550683625 1.56651240 2.16309257

[160,] 0.611507227 0.78093816 3.93593413

[161,] -0.781996598 2.25494970 4.56839198

[162,] -1.168058034 0.77338779 3.55612027

[163,] 0.799700704 0.52551095 1.19594549

[164,] 1.575984987 2.08152053 1.61531745

[165,] -0.444010838 2.23316925 4.39022878

[166,] 0.451781418 1.94786607 4.49131492

[167,] 1.820649007 1.34871068 1.84915535

[168,] 0.486116825 -0.08966674 2.29185943

[169,] -1.597448337 1.99343650 2.54283071

[170,] 1.406026501 1.10381707 2.98398717

[171,] -0.771297698 1.65729296 4.27832600

[172,] -0.823815019 1.57210561 0.15588529

[173,] 0.455494017 0.50858806 2.14455073

[174,] -0.733691192 2.45613400 4.26892838

[175,] -1.561767959 0.61493427 1.74118854

[176,] 1.286009567 2.61273101 2.13418176

[177,] -0.669213439 0.88904660 2.00011447

[178,] -0.246640602 -0.49170688 0.36588276

[179,] 1.538600648 0.88839563 4.32057647

[180,] 0.115351608 1.65555212 1.88572084

[181,] -0.244463727 2.47929964 5.08157513

[182,] 1.772383685 3.64204787 4.26612021

[183,] 0.179553152 1.54936635 3.01447353

[184,] 0.498189792 0.74987854 1.14459587

[185,] -0.818815545 2.77259575 3.37003140

[186,] 0.001236091 0.48592155 0.30838826

[187,] -1.305836254 1.04304205 3.01295430

[188,] -1.969358990 0.57789784 3.51117417

[189,] -0.117007471 0.87852640 0.96208771

[190,] -2.068885634 -0.72010732 1.86110613

[191,] 0.133402910 1.10128123 4.31822071

[192,] -0.620241746 0.49035509 0.42660427

[193,] 1.555645427 2.93196781 3.98096273

[194,] 0.207132669 1.44300830 2.56339129

[195,] -0.531332263 0.87646155 1.44038630

[196,] -0.450852624 0.69844353 2.10723886

[197,] -0.578033524 -0.22342311 0.93893172

[198,] 1.939771679 1.33714619 2.55683098

[199,] -0.902142641 1.35310907 1.88484939

[200,] 0.983640670 2.71220474 3.89316641

> #fin gives simulated values from the required muktivariate normal distribution

> m=rep(0,3)

> for(i in 1:3)

+ {

+ m[i]=mean(fin[,i])

+ }

> m

[1] -0.06864944 1.05297530 2.09011268

>

> var(cbind(fin[,1:2]))

          [,1]      [,2]

[1,] 1.2687155 0.4193914

[2,] 0.4193914 1.4407019

> var(cbind(fin[,2:3]))

          [,1]      [,2]

[1,] 1.4407019 0.6443866

[2,] 0.6443866 1.6897128

> var(cbind(fin[,1],fin[,3]))

           [,1]       [,2]

[1,] 1.2687155 -0.2288229

[2,] -0.2288229 1.6897128

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote