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

Question 4 [10 points] a) Randomly generate 100 numbers from an exponential dist

ID: 3057547 • Letter: Q

Question

Question 4 [10 points] a) Randomly generate 100 numbers from an exponential distribution with rate 1, and store those numbers in y1. Generate another 100 random numbers from a I(1, 2) distribution, and store those numbers in y2. Use a formal statistical test to check whethe y1 follows a normal distribution. Do the same for y2. b) Perform a non-parametric test to check whether the distribution of y1 is the same as y2. Recall from the lecture notes that if two non-normal distributions have the same general shape and we want to test whether their location is the same, we use the rank-sum test. Calculate the rank-sum test statistic U, c) Conduct a two-sided wiloxon test and write your findings

Explanation / Answer

##a)

> y1=rexp(100,1)

> y1

[1] 0.83360735 0.89405926 2.43390814 0.02252989 1.09916309 2.98347153

[7] 0.02725340 0.54722645 0.82692260 1.04913300 2.60928433 0.51573707

[13] 2.84316845 1.25236849 2.57504903 1.83730864 0.19919551 0.17683002

[19] 0.61654056 0.20420597 0.25029626 0.41415561 0.28893983 0.28223959

[25] 1.15466437 2.32610184 1.27570010 0.05934686 0.51466553 0.58872821

[31] 0.60915942 0.51913933 0.90265831 0.11847583 1.61164500 1.76632465

[37] 1.71278890 1.48005890 2.26663431 0.08513016 0.97489756 2.40240617

[43] 0.04693626 0.37564715 2.04983967 1.27418741 0.46227392 0.21087652

[49] 0.47279538 0.46976173 0.25918455 0.66276311 0.55748282 0.26622158

[55] 1.05725587 0.77600866 4.52911477 1.07319579 0.39214563 1.87849395

[61] 0.39452063 0.36093409 0.03286512 1.20663429 2.77788123 3.60017213

[67] 0.17263147 1.15139554 0.26927597 1.15663684 0.47124263 0.20994838

[73] 2.28404208 0.72572661 1.81803183 0.57398693 1.47312656 0.38492564

[79] 0.35587015 2.63802722 0.90747734 2.24164985 2.90102080 1.78111279

[85] 0.20070232 0.62472498 1.11084524 0.16462102 1.06900912 0.27081861

[91] 1.92547301 0.08441561 3.18685773 2.15639358 0.06121788 0.53437073

[97] 0.68783868 1.25301833 2.50766315 0.01030147

H0: The random samples are normally distributed.

shapiro.test(y1)

        Shapiro-Wilk normality test

data: y1

W = 0.88241, p-value = 2.298e-07

INTERPRETATION: here p- value = 2.298e-07 is less than alpha=0.05, hence H0 is rejected .therefore the random samples are not normally distributed.

> y2=rgamma(100,1,2)

> y2

[1] 0.909417490 0.206004349 0.074978819 0.203574148 0.236171884 0.117498060

[7] 0.592105770 2.020429655 0.130190995 0.304617275 0.235314524 0.712028580

[13] 0.919384844 0.400993513 0.171680634 0.408474806 0.530265831 0.066061574

[19] 1.045005088 0.991932623 0.083036101 0.826942039 0.018965952 0.683311102

[25] 0.162094714 0.679839043 0.463698806 0.080816200 0.253652263 0.762723597

[31] 1.430635337 0.546508299 0.386035942 1.310684540 0.259960548 0.092818045

[37] 2.942768202 1.106925617 0.039302291 0.093574303 0.007051900 0.085480888

[43] 0.743138396 0.433646447 0.401383042 1.183122273 0.327920485 0.057077628

[49] 0.384931746 0.107758628 0.119386359 0.474429616 0.008293007 0.524134459

[55] 0.854965843 0.457327230 1.727159798 0.122341521 0.168382017 0.226753545

[61] 0.095612763 0.037363504 0.068858077 0.477615418 0.088563446 0.437556877

[67] 0.098977626 2.515441359 0.568278227 0.272417147 1.096826531 0.929967421

[73] 0.290011028 0.549876013 0.575452730 0.610827978 0.766007436 1.272983992

[79] 0.372057649 0.519476377 1.247731019 0.013205127 0.035976349 0.290526107

[85] 0.124267122 0.990195136 0.252704541 0.213378320 0.963702294 0.033410358

[91] 0.954577020 0.952856832 2.246654454 1.293367634 0.309927178 0.827685085

[97] 0.570166092 0.190407548 0.138942802 1.792238620

H0: The random samples are normally distributed.

> shapiro.test(y2)

        Shapiro-Wilk normality test

data: y2

W = 0.81947, p-value = 1.028e-09

INTERPRETATION: here p-value = 1.028e-09 is less than alpha=0.05, hence H0 is rejected .therefore the

random samples are not normally distributed.

##b)

> H0: y1 and y2 has same distribution

> ks.test(y1,y2)

        Two-sample Kolmogorov-Smirnov test

data: y1 and y2

D = 0.29, p-value = 0.0004453

alternative hypothesis: two-sided

INTERPRETATION: here p-value = 0.0004453 is less than alpha=0.05, hence H0 is rejected .therefore the

random samples does not follow same distribution.

wilcox.test(y1,y2,alternative="two.sided")

##c)

        Wilcoxon rank sum test with continuity correction

data: y1 and y2

W = 6673, p-value = 4.378e-05

alternative hypothesis: true location shift is not equal to 0

>

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