plot.permutationTest.Rd
Plot the results of calling functions that return an object of class
"permutationTest"
. Currently, the EnvStats functions that perform
permutation tests and produce objects of class "permutationTest"
are: oneSamplePermutationTest
,
twoSamplePermutationTestLocation
, and twoSamplePermutationTestProportion
.
The function plot.permutationTest
is automatically called by
plot
when given an object of class "permutationTest"
.
an object of class "permutationTest"
.
See permutationTest.object
for details.
a character string or numeric scalar determining the color of the histogram
used to display the permutation distribution. The default
value is hist.col="cyan"
. See the entry for col
in the
R help file for par
for more information.
a character string or numeric scalar determining the color of the line indicating
the value of the observed test statistic. The default value is
stat.col="black"
. See the entry for col
in the R help file for
par
for more information.
numeric scalar determining the width of the line indicating the value of the
observed test statistic. The default value is stat.lwd=3*par("cex")
.
See the entry for lwd
in the R help file for par
for
more information.
numeric scalar determining the line type used to display the value of the
observed test statistic. The default value is stat.lty=1
.
See the entry for lty
in the R help file for par
for
more information.
scalar indicating how many significant digits to print for the distribution
parameters. The default value is .Options$digits
(i.e., the current
setting of options("digits")
).
graphics parameters. See the help file for par
.
Produces a plot displaying the permutation distribution (exact=TRUE
) or a
sample of the permutation distribution (exact=FALSE
), and a line indicating
the observed value of the test statistic. The title in the plot includes
information on the data used, null hypothesis, and p-value.
The function plot.permutationTest
is a method for the generic function
plot
for the class "permutationTest"
(see permutationTest.object
). It can be invoked by calling
plot
and giving it an object of
class "permutationTest"
as the first argument, or by calling plot.permutationTest
directly, regardless of the class of the object given
as the first argument to plot.permutationTest
.
plot.permutationTest
invisibly returns the first argument, x
.
Chambers, J. M. and Hastie, T. J. (1992). Statistical Models in S. Wadsworth & Brooks/Cole.
# Create an object of class "permutationTest", then print it and plot it.
# (Note: the call to set.seed() allows you to reproduce this example.)
#------------------------------------------------------------------------
set.seed(23)
dat <- rlogis(10, location = 7, scale = 2)
permutationTest.obj <- oneSamplePermutationTest(dat, mu = 5,
alternative = "greater", exact = TRUE)
mode(permutationTest.obj)
#> [1] "list"
#[1] "list"
class(permutationTest.obj)
#> [1] "permutationTest"
#[1] "permutationTest"
names(permutationTest.obj)
#> [1] "statistic" "parameters" "p.value"
#> [4] "estimate" "null.value" "alternative"
#> [7] "method" "estimation.method" "sample.size"
#> [10] "data.name" "bad.obs" "stat.dist"
#> [13] "exact"
# [1] "statistic" "parameters" "p.value"
# [4] "estimate" "null.value" "alternative"
# [7] "method" "estimation.method" "sample.size"
#[10] "data.name" "bad.obs" "stat.dist"
#[13] "exact"
#==========
# Print the results of the test
#------------------------------
permutationTest.obj
#> $statistic
#> Sum(x - 5)
#> 49.77294
#>
#> $parameters
#> NULL
#>
#> $p.value
#> [1] 0.001953125
#>
#> $estimate
#> Mean
#> 9.977294
#>
#> $null.value
#> Mean (Median)
#> 5
#>
#> $alternative
#> [1] "greater"
#>
#> $method
#> [1] "One-Sample Permutation Test\n (Exact)"
#>
#> $estimation.method
#> NULL
#>
#> $sample.size
#> n
#> 10
#>
#> $data.name
#> [1] "dat"
#>
#> $bad.obs
#> [1] 0
#>
#> $stat.dist
#> [1] -50.76433285 -45.52894718 -49.77294023 -44.53755456 -49.56281095
#> [6] -44.32742528 -48.57141833 -43.33603266 -43.16871044 -37.93332477
#> [11] -42.17731782 -36.94193215 -41.96718854 -36.73180287 -40.97579592
#> [16] -35.74041025 -40.71385853 -35.47847286 -39.72246591 -34.48708024
#> [21] -39.51233663 -34.27695096 -38.52094401 -33.28555834 -33.11823612
#> [26] -27.88285045 -32.12684350 -26.89145783 -31.91671422 -26.68132855
#> [31] -30.92532160 -25.68993593 -47.99440683 -42.75902117 -47.00301421
#> [36] -41.76762855 -46.79288494 -41.55749927 -45.80149231 -40.56610665
#> [41] -40.39878442 -35.16339876 -39.40739180 -34.17200614 -39.19726253
#> [46] -33.96187686 -38.20586990 -32.97048424 -37.94393251 -32.70854685
#> [51] -36.95253989 -31.71715423 -36.74241062 -31.50702495 -35.75101800
#> [56] -30.51563233 -30.34831010 -25.11292444 -29.35691748 -24.12153182
#> [61] -29.14678821 -23.91140254 -28.15539559 -22.92000992 -33.66622188
#> [66] -28.43083622 -32.67482926 -27.43944360 -32.46469999 -27.22931432
#> [71] -31.47330737 -26.23792170 -26.07059947 -20.83521381 -25.07920685
#> [76] -19.84382119 -24.86907758 -19.63369191 -23.87768495 -18.64229929
#> [81] -23.61574757 -18.38036190 -22.62435494 -17.38896928 -22.41422567
#> [86] -17.17884000 -21.42283305 -16.18744738 -16.02012516 -10.78473949
#> [91] -15.02873253 -9.79334687 -14.81860326 -9.58321759 -13.82721064
#> [96] -8.59182497 -30.89629587 -25.66091020 -29.90490325 -24.66951758
#> [101] -29.69477397 -24.45938830 -28.70338135 -23.46799568 -23.30067346
#> [106] -18.06528779 -22.30928084 -17.07389517 -22.09915156 -16.86376589
#> [111] -21.10775894 -15.87237327 -20.84582155 -15.61043588 -19.85442893
#> [116] -14.61904326 -19.64429965 -14.40891398 -18.65290703 -13.41752136
#> [121] -13.25019914 -8.01481347 -12.25880652 -7.02342085 -12.04867724
#> [126] -6.81329157 -11.05728462 -5.82189895 -31.56214932 -26.32676365
#> [131] -30.57075670 -25.33537103 -30.36062742 -25.12524175 -29.36923480
#> [136] -24.13384913 -23.96652691 -18.73114124 -22.97513429 -17.73974862
#> [141] -22.76500501 -17.52961934 -21.77361239 -16.53822672 -21.51167500
#> [146] -16.27628933 -20.52028238 -15.28489671 -20.31015310 -15.07476743
#> [151] -19.31876048 -14.08337481 -13.91605259 -8.68066692 -12.92465997
#> [156] -7.68927430 -12.71453069 -7.47914502 -11.72313807 -6.48775240
#> [161] -28.79222330 -23.55683763 -27.80083068 -22.56544501 -27.59070140
#> [166] -22.35531574 -26.59930878 -21.36392312 -21.19660089 -15.96121522
#> [171] -20.20520827 -14.96982260 -19.99507899 -14.75969333 -19.00368637
#> [176] -13.76830071 -18.74174898 -13.50636332 -17.75035636 -12.51497070
#> [181] -17.54022708 -12.30484142 -16.54883446 -11.31344880 -11.14612657
#> [186] -5.91074091 -10.15473395 -4.91934829 -9.94460467 -4.70921901
#> [191] -8.95321205 -3.71782639 -14.46403835 -9.22865269 -13.47264573
#> [196] -8.23726006 -13.26251645 -8.02713079 -12.27112383 -7.03573817
#> [201] -6.86841594 -1.63303028 -5.87702332 -0.64163765 -5.66689404
#> [206] -0.43150838 -4.67550142 0.55988424 -4.41356403 0.82182163
#> [211] -3.42217141 1.81321425 -3.21204214 2.02334353 -2.22064951
#> [216] 3.01473615 3.18205838 8.41744404 4.17345100 9.40883666
#> [221] 4.38358027 9.61896594 5.37497290 10.61035856 -11.69411234
#> [226] -6.45872667 -10.70271972 -5.46733405 -10.49259044 -5.25720477
#> [231] -9.50119782 -4.26581215 -4.09848993 1.13689574 -3.10709731
#> [236] 2.12828836 -2.89696803 2.33841764 -1.90557541 3.32981026
#> [241] -1.64363802 3.59174765 -0.65224540 4.58314027 -0.44211612
#> [246] 4.79326955 0.54927650 5.78466217 5.95198439 11.18737006
#> [251] 6.94337701 12.17876268 7.15350629 12.38889196 8.14489891
#> [256] 13.38028458 -40.11586786 -34.88048219 -39.12447524 -33.88908957
#> [261] -38.91434596 -33.67896029 -37.92295334 -32.68756767 -32.52024545
#> [266] -27.28485978 -31.52885283 -26.29346716 -31.31872355 -26.08333788
#> [271] -30.32733093 -25.09194526 -30.06539354 -24.83000787 -29.07400092
#> [276] -23.83861525 -28.86387164 -23.62848597 -27.87247902 -22.63709335
#> [281] -22.46977113 -17.23438546 -21.47837851 -16.24299284 -21.26824923
#> [286] -16.03286356 -20.27685661 -15.04147094 -37.34594185 -32.11055618
#> [291] -36.35454923 -31.11916356 -36.14441995 -30.90903428 -35.15302733
#> [296] -29.91764166 -29.75031944 -24.51493377 -28.75892682 -23.52354115
#> [301] -28.54879754 -23.31341187 -27.55740492 -22.32201925 -27.29546753
#> [306] -22.06008186 -26.30407491 -21.06868924 -26.09394563 -20.85855996
#> [311] -25.10255301 -19.86716734 -19.69984512 -14.46445945 -18.70845250
#> [316] -13.47306683 -18.49832322 -13.26293755 -17.50693060 -12.27154493
#> [321] -23.01775690 -17.78237123 -22.02636428 -16.79097861 -21.81623500
#> [326] -16.58084933 -20.82484238 -15.58945671 -15.42213449 -10.18674882
#> [331] -14.43074187 -9.19535620 -14.22061259 -8.98522692 -13.22921997
#> [336] -7.99383430 -12.96728258 -7.73189691 -11.97588996 -6.74050429
#> [341] -11.76576068 -6.53037501 -10.77436806 -5.53898239 -5.37166017
#> [346] -0.13627450 -4.38026755 0.85511812 -4.17013827 1.06524740
#> [351] -3.17874565 2.05664002 -20.24783088 -15.01244522 -19.25643826
#> [356] -14.02105260 -19.04630899 -13.81092332 -18.05491636 -12.81953070
#> [361] -12.65220847 -7.41682281 -11.66081585 -6.42543019 -11.45068658
#> [366] -6.21530091 -10.45929395 -5.22390829 -10.19735656 -4.96197090
#> [371] -9.20596394 -3.97057828 -8.99583467 -3.76044900 -8.00444205
#> [376] -2.76905638 -2.60173415 2.63365151 -1.61034153 3.62504413
#> [381] -1.40021226 3.83517341 -0.40881964 4.82656603 -20.91368433
#> [386] -15.67829866 -19.92229171 -14.68690604 -19.71216243 -14.47677676
#> [391] -18.72076981 -13.48538414 -13.31806192 -8.08267625 -12.32666930
#> [396] -7.09128363 -12.11654002 -6.88115435 -11.12514740 -5.88976173
#> [401] -10.86321001 -5.62782434 -9.87181739 -4.63643172 -9.66168811
#> [406] -4.42630244 -8.67029549 -3.43490982 -3.26758760 1.96779807
#> [411] -2.27619498 2.95919069 -2.06606570 3.16931997 -1.07467308
#> [416] 4.16071259 -18.14375832 -12.90837265 -17.15236570 -11.91698003
#> [421] -16.94223642 -11.70685075 -15.95084380 -10.71545813 -10.54813591
#> [426] -5.31275024 -9.55674329 -4.32135762 -9.34661401 -4.11122834
#> [431] -8.35522139 -3.11983572 -8.09328400 -2.85789833 -7.10189138
#> [436] -1.86650571 -6.89176210 -1.65637643 -5.90036948 -0.66498381
#> [441] -0.49766159 4.73772408 0.49373103 5.72911670 0.70386031
#> [446] 5.93924598 1.69525293 6.93063860 -3.81557337 1.41981230
#> [451] -2.82418075 2.41120492 -2.61405147 2.62133420 -1.62265885
#> [456] 3.61272682 3.78004904 9.01543471 4.77144166 10.00682733
#> [461] 4.98157094 10.21695661 5.97296356 11.20834923 6.23490095
#> [466] 11.47028662 7.22629357 12.46167924 7.43642285 12.67180852
#> [471] 8.42781547 13.66320114 13.83052336 19.06590903 14.82191598
#> [476] 20.05730165 15.03204526 20.26743093 16.02343788 21.25882355
#> [481] -1.04564735 4.18973832 -0.05425473 5.18113094 0.15587455
#> [486] 5.39126021 1.14726717 6.38265283 6.54997506 11.78536073
#> [491] 7.54136768 12.77675335 7.75149696 12.98688262 8.74288958
#> [496] 13.97827524 9.00482697 14.24021263 9.99621959 15.23160525
#> [501] 10.20634887 15.44173453 11.19774149 16.43312715 16.60044938
#> [506] 21.83583504 17.59184200 22.82722767 17.80197128 23.03735694
#> [511] 18.79336390 24.02874956 -24.02874956 -18.79336390 -23.03735694
#> [516] -17.80197128 -22.82722767 -17.59184200 -21.83583504 -16.60044938
#> [521] -16.43312715 -11.19774149 -15.44173453 -10.20634887 -15.23160525
#> [526] -9.99621959 -14.24021263 -9.00482697 -13.97827524 -8.74288958
#> [531] -12.98688262 -7.75149696 -12.77675335 -7.54136768 -11.78536073
#> [536] -6.54997506 -6.38265283 -1.14726717 -5.39126021 -0.15587455
#> [541] -5.18113094 0.05425473 -4.18973832 1.04564735 -21.25882355
#> [546] -16.02343788 -20.26743093 -15.03204526 -20.05730165 -14.82191598
#> [551] -19.06590903 -13.83052336 -13.66320114 -8.42781547 -12.67180852
#> [556] -7.43642285 -12.46167924 -7.22629357 -11.47028662 -6.23490095
#> [561] -11.20834923 -5.97296356 -10.21695661 -4.98157094 -10.00682733
#> [566] -4.77144166 -9.01543471 -3.78004904 -3.61272682 1.62265885
#> [571] -2.62133420 2.61405147 -2.41120492 2.82418075 -1.41981230
#> [576] 3.81557337 -6.93063860 -1.69525293 -5.93924598 -0.70386031
#> [581] -5.72911670 -0.49373103 -4.73772408 0.49766159 0.66498381
#> [586] 5.90036948 1.65637643 6.89176210 1.86650571 7.10189138
#> [591] 2.85789833 8.09328400 3.11983572 8.35522139 4.11122834
#> [596] 9.34661401 4.32135762 9.55674329 5.31275024 10.54813591
#> [601] 10.71545813 15.95084380 11.70685075 16.94223642 11.91698003
#> [606] 17.15236570 12.90837265 18.14375832 -4.16071259 1.07467308
#> [611] -3.16931997 2.06606570 -2.95919069 2.27619498 -1.96779807
#> [616] 3.26758760 3.43490982 8.67029549 4.42630244 9.66168811
#> [621] 4.63643172 9.87181739 5.62782434 10.86321001 5.88976173
#> [626] 11.12514740 6.88115435 12.11654002 7.09128363 12.32666930
#> [631] 8.08267625 13.31806192 13.48538414 18.72076981 14.47677676
#> [636] 19.71216243 14.68690604 19.92229171 15.67829866 20.91368433
#> [641] -4.82656603 0.40881964 -3.83517341 1.40021226 -3.62504413
#> [646] 1.61034153 -2.63365151 2.60173415 2.76905638 8.00444205
#> [651] 3.76044900 8.99583467 3.97057828 9.20596394 4.96197090
#> [656] 10.19735656 5.22390829 10.45929395 6.21530091 11.45068658
#> [661] 6.42543019 11.66081585 7.41682281 12.65220847 12.81953070
#> [666] 18.05491636 13.81092332 19.04630899 14.02105260 19.25643826
#> [671] 15.01244522 20.24783088 -2.05664002 3.17874565 -1.06524740
#> [676] 4.17013827 -0.85511812 4.38026755 0.13627450 5.37166017
#> [681] 5.53898239 10.77436806 6.53037501 11.76576068 6.74050429
#> [686] 11.97588996 7.73189691 12.96728258 7.99383430 13.22921997
#> [691] 8.98522692 14.22061259 9.19535620 14.43074187 10.18674882
#> [696] 15.42213449 15.58945671 20.82484238 16.58084933 21.81623500
#> [701] 16.79097861 22.02636428 17.78237123 23.01775690 12.27154493
#> [706] 17.50693060 13.26293755 18.49832322 13.47306683 18.70845250
#> [711] 14.46445945 19.69984512 19.86716734 25.10255301 20.85855996
#> [716] 26.09394563 21.06868924 26.30407491 22.06008186 27.29546753
#> [721] 22.32201925 27.55740492 23.31341187 28.54879754 23.52354115
#> [726] 28.75892682 24.51493377 29.75031944 29.91764166 35.15302733
#> [731] 30.90903428 36.14441995 31.11916356 36.35454923 32.11055618
#> [736] 37.34594185 15.04147094 20.27685661 16.03286356 21.26824923
#> [741] 16.24299284 21.47837851 17.23438546 22.46977113 22.63709335
#> [746] 27.87247902 23.62848597 28.86387164 23.83861525 29.07400092
#> [751] 24.83000787 30.06539354 25.09194526 30.32733093 26.08333788
#> [756] 31.31872355 26.29346716 31.52885283 27.28485978 32.52024545
#> [761] 32.68756767 37.92295334 33.67896029 38.91434596 33.88908957
#> [766] 39.12447524 34.88048219 40.11586786 -13.38028458 -8.14489891
#> [771] -12.38889196 -7.15350629 -12.17876268 -6.94337701 -11.18737006
#> [776] -5.95198439 -5.78466217 -0.54927650 -4.79326955 0.44211612
#> [781] -4.58314027 0.65224540 -3.59174765 1.64363802 -3.32981026
#> [786] 1.90557541 -2.33841764 2.89696803 -2.12828836 3.10709731
#> [791] -1.13689574 4.09848993 4.26581215 9.50119782 5.25720477
#> [796] 10.49259044 5.46733405 10.70271972 6.45872667 11.69411234
#> [801] -10.61035856 -5.37497290 -9.61896594 -4.38358027 -9.40883666
#> [806] -4.17345100 -8.41744404 -3.18205838 -3.01473615 2.22064951
#> [811] -2.02334353 3.21204214 -1.81321425 3.42217141 -0.82182163
#> [816] 4.41356403 -0.55988424 4.67550142 0.43150838 5.66689404
#> [821] 0.64163765 5.87702332 1.63303028 6.86841594 7.03573817
#> [826] 12.27112383 8.02713079 13.26251645 8.23726006 13.47264573
#> [831] 9.22865269 14.46403835 3.71782639 8.95321205 4.70921901
#> [836] 9.94460467 4.91934829 10.15473395 5.91074091 11.14612657
#> [841] 11.31344880 16.54883446 12.30484142 17.54022708 12.51497070
#> [846] 17.75035636 13.50636332 18.74174898 13.76830071 19.00368637
#> [851] 14.75969333 19.99507899 14.96982260 20.20520827 15.96121522
#> [856] 21.19660089 21.36392312 26.59930878 22.35531574 27.59070140
#> [861] 22.56544501 27.80083068 23.55683763 28.79222330 6.48775240
#> [866] 11.72313807 7.47914502 12.71453069 7.68927430 12.92465997
#> [871] 8.68066692 13.91605259 14.08337481 19.31876048 15.07476743
#> [876] 20.31015310 15.28489671 20.52028238 16.27628933 21.51167500
#> [881] 16.53822672 21.77361239 17.52961934 22.76500501 17.73974862
#> [886] 22.97513429 18.73114124 23.96652691 24.13384913 29.36923480
#> [891] 25.12524175 30.36062742 25.33537103 30.57075670 26.32676365
#> [896] 31.56214932 5.82189895 11.05728462 6.81329157 12.04867724
#> [901] 7.02342085 12.25880652 8.01481347 13.25019914 13.41752136
#> [906] 18.65290703 14.40891398 19.64429965 14.61904326 19.85442893
#> [911] 15.61043588 20.84582155 15.87237327 21.10775894 16.86376589
#> [916] 22.09915156 17.07389517 22.30928084 18.06528779 23.30067346
#> [921] 23.46799568 28.70338135 24.45938830 29.69477397 24.66951758
#> [926] 29.90490325 25.66091020 30.89629587 8.59182497 13.82721064
#> [931] 9.58321759 14.81860326 9.79334687 15.02873253 10.78473949
#> [936] 16.02012516 16.18744738 21.42283305 17.17884000 22.41422567
#> [941] 17.38896928 22.62435494 18.38036190 23.61574757 18.64229929
#> [946] 23.87768495 19.63369191 24.86907758 19.84382119 25.07920685
#> [951] 20.83521381 26.07059947 26.23792170 31.47330737 27.22931432
#> [956] 32.46469999 27.43944360 32.67482926 28.43083622 33.66622188
#> [961] 22.92000992 28.15539559 23.91140254 29.14678821 24.12153182
#> [966] 29.35691748 25.11292444 30.34831010 30.51563233 35.75101800
#> [971] 31.50702495 36.74241062 31.71715423 36.95253989 32.70854685
#> [976] 37.94393251 32.97048424 38.20586990 33.96187686 39.19726253
#> [981] 34.17200614 39.40739180 35.16339876 40.39878442 40.56610665
#> [986] 45.80149231 41.55749927 46.79288494 41.76762855 47.00301421
#> [991] 42.75902117 47.99440683 25.68993593 30.92532160 26.68132855
#> [996] 31.91671422 26.89145783 32.12684350 27.88285045 33.11823612
#> [1001] 33.28555834 38.52094401 34.27695096 39.51233663 34.48708024
#> [1006] 39.72246591 35.47847286 40.71385853 35.74041025 40.97579592
#> [1011] 36.73180287 41.96718854 36.94193215 42.17731782 37.93332477
#> [1016] 43.16871044 43.33603266 48.57141833 44.32742528 49.56281095
#> [1021] 44.53755456 49.77294023 45.52894718 50.76433285
#>
#> $exact
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "permutationTest"
#Results of Hypothesis Test
#--------------------------
#
#Null Hypothesis: Mean (Median) = 5
#
#Alternative Hypothesis: True Mean (Median) is greater than 5
#
#Test Name: One-Sample Permutation Test
# (Exact)
#
#Estimated Parameter(s): Mean = 9.977294
#
#Data: dat
#
#Sample Size: 10
#
#Test Statistic: Sum(x - 5) = 49.77294
#
#P-value: 0.001953125
#==========
# Plot the results of the test
#-----------------------------
dev.new()
plot(permutationTest.obj)
#==========
# Extract the test statistic
#---------------------------
permutationTest.obj$statistic
#> Sum(x - 5)
#> 49.77294
#Sum(x - 5)
# 49.77294
#==========
# Clean up
#---------
rm(permutationTest.obj)
graphics.off()