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

Bonus Using permutation test SAS code , do the following: Trauma data Metabolic

ID: 3071185 • Letter: B

Question

Bonus

Using permutation test SAS code , do the following:

Trauma data

Metabolic Expenditure

Nontrauma patients: 20.1 22.9 18.8 20.9 20.9 22.7 21.4 20

trauma patients: 38.5 25.8 22 23 37.6 30 24.5

Part A

Build the permutation distribution (using 5,000 permutations) for the rank sum statistic for the Trauma

data used above. Use SAS to fit/overlay a normal curve to the resulting histogram. Compare the mean and

standard deviation of this normal curve that was fit to the permutation/randomization distribution to the

mu and sigma you found earlier in the homework.

Part B

Compare the one-sided p-value found in this permutation distribution with the one found in prior questions.

Explanation / Answer

We shall use R to answer this

Nontrauma<- c(20.1,22.9,18.8,20.9,20.9,22.7,21.4,20)
Trauma<-c(38.5,25.8,22,23,37.6,30,24.5)

# rank functions
rank(Nontrauma)
rank(Trauma)

# z stats is x-mean/sd

mtr<-mean(Trauma)
SDtr<-sd(Trauma)

zTrauma<- (Trauma-mtr)/SDtr

# for non trauma patients

mntr<-mean(Nontrauma)
SDntr<-sd(Nontrauma)

zNonTrauma<- (Nontrauma-mntr)/SDntr

# wilcox test for the patients
wilcox.test(Nontrauma,Trauma)


# medians for the patients

medTrauma<- median(Trauma)
medNTrauma <- median(Nontrauma)


# write a function in R for Z test
z.test = function(a, mu, var){
zeta = (mean(a) - mu) / (sqrt(var / length(a)))
return(zeta)
}

z.test(Trauma,medTrauma,SDtr^2)
z.test(Nontrauma,medNTrauma,SDntr^2)

The results of the above snippet are

> rank(Nontrauma)
[1] 3.0 8.0 1.0 4.5 4.5 7.0 6.0 2.0
> rank(Trauma)
[1] 7 4 1 2 6 5 3

> mtr
[1] 28.77143
> SDtr
[1] 6.835377
> zTrauma
[1] 1.4232677 -0.4347132 -0.9906445 -0.8443468 1.2915997 0.1797372 -0.6249002

> mntr
[1] 20.9625
> SDntr
[1] 1.379376
> zNonTrauma
[1] -0.62528267 1.40462048 -1.56773770 -0.04531034 -0.04531034 1.25962740
[7] 0.31717237 -0.69777921

> wilcox.test(Nontrauma,Trauma)

   Wilcoxon rank sum test with continuity correction

data: Nontrauma and Trauma
W = 2, p-value = 0.00314
alternative hypothesis: true location shift is not equal to 0

> z.test(Trauma,medTrauma,SDtr^2)
[1] 1.150143
> z.test(Nontrauma,medNTrauma,SDntr^2)
[1] 0.128157