. This is Dataplot macro LEVENE.DP
. Purpose--Carry out Levene's Test for 1-way Shift in Variation
. Input --Y = vector of observations
. --X = vector of group tags
. Output--statval = value of Levene's F statistic
. statvalc = cdf value (0.0 to 1.0) of statva
. (values larger that .95 => signficance)
.
feedback off
.
. Step 1--Compute counts
.
let n = number y
let xdis = distinct x
let k = number xdis
.
. Step 2--Form medians & then Levene's transformed variable
.
loop for i = 1 1 k
let xi = xdis(i)
let medi = median y subset x xi
let ymediv = medi subset x xi
end loop
let t = abs(y-ymediv)
.
. Step 3--From here on out, do the usual ANOVA F test
. on the transformed variable.
. Start by computing means.
.
let tbar = mean y
let tbarv = tbar for i = 1 1 n
loop for i = 1 1 k
let xi = xdis(i)
let mi = mean y subset x xi
let tbariv = mi subset x xi
end loop
.
. Step 4--Compute the F statistic
.
let numdel = (tbariv - tbarv)**2
let numssq = sum numdel
let numdf = k-1
let numms = numssq/numdf
.
let dendel = (t - tbariv)**2
let denssq = sum dendel
let dendf = n-k
let denms = denssq/dendf
.
let statval = numms/denms
let statvalc = fcdf(statval,numdf,dendf)
.
. Step 5--Compute percent point values from the reference F distribution
.
let km1 = k-1
let nmk = n-k
let cutoff0 = 0
let cutoff50 = fppf(.50,km1,nmk)
let cutoff75 = fppf(.75,km1,nmk)
let cutoff90 = fppf(.90,km1,nmk)
let cutoff95 = fppf(.95,km1,nmk)
let cutoff99 = fppf(.99,km1,nmk)
let cutof999 = fppf(.999,km1,nmk)
.
. Step 6--Write everything out
.
write " "
write " ______________________________________"
write " "
write " Levene's F Test for Shift in Variation"
write " (Assumption: Normality)"
write " CALL LEVENE.DP"
write " ______________________________________"
set write decimals 6
write " "
write " 1. Statistics"
write " Number of Observations = ^n"
write " Number of Groups = ^k"
write " "
write " Levene's F Test Statistic = ^statval "
.
write " "
write " 2. Percent Points of the Reference Distribution"
write " for Levene's Test Statistic:"
write " 0 % Point: ^cutoff0"
write " 50 % Point: ^cutoff50"
write " 75 % Point: ^cutoff75"
write " 90 % Point: ^cutoff90"
write " 95 % Point: ^cutoff95"
write " 99 % Point: ^cutoff99"
write " 99.9 % Point: ^cutof999"
write " "
let cdf2 = 100*statvalc
let cdf2 = round(cdf2,6)
write " ^cdf2 % Point: ^statval"
.
write " "
write " 3. Conclusion (at the 5% level):"
if statval < cutoff95
write " There is no shift in variation."
write " Thus: Homogenous wrt variation."
end if
if statval >= cutoff95
write " There is a shift in variation."
write " Thus: Not homogenous wrt variation."
end if
write " "
.
. Step 7--Do housekeeping--delete intermediate parameters and variables
.
delete cutoff0 cutoff50 cutoff75 cutoff90 cutoff95 cutoff99 cutof999
delete n k ybar i xi mi
delete numssq numdf numms
delete denssq dendf denms
delete km1 nmk
delete numdel dendel xdis ybarv ybariv
delete medi tbar ymediv t tbarv tabariv
.
feedback on