# st: R: permute test statistic

 From "Carlo Lazzaro" To Subject st: R: permute test statistic Date Thu, 30 Apr 2009 19:18:50 +0200

```Dear Hugh,
what follows might be of interest:

---------------------begin example----------------------------
ttest Mod, by(Index) unequal
permute Mod (r(mu_1)-r(mu_2)), reps(100) saving(C:\Documents and
Settings\carlo\Desktop\alfa.dta,every(1) replace) strata(Index) : ttest Mod,
by(Index) unequal
use "C:\Documents and Settings\carlo\Desktop\alfa.dta", clear
(permute Mod : ttest)
count if  _pm_1>r(mu_1)-r(mu_2)
---------------------end example----------------------------
Besides, I am going to send you off the list an article on this topic that I
have found useful in the past.

HTH and Kind Regards,
Carlo
-----Messaggio originale-----
Da: Hugh Robinson [mailto:hugh.robinson@umontana.edu]
Inviato: giovedì 30 aprile 2009 18.45
A: Carlo Lazzaro; statalist@hsphsun2.harvard.edu
Oggetto: RE: permute test statistic

That works.  If I understand correctly, this code is asking stata to
randomly sample my mod values and run a ttest on that random sample.

The (r(mu_1)-r(mu_2)) exp_list creates the proper test statistic.  However,
does using a t-test as the command make my results reliant on the number of
samples or reps I choose?  The top of my 95% CI, below, will reduce to 0.003
if I run 1000 replications rather than 100.

Do you know what command I would use to simply count the number of
permutations that have a value greater than (r(mu_1)-r(mu_2))?

Permutation replications (100)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50
..................................................   100

Monte Carlo permutation results

Number of strata =          0                     Number of obs   =
20000

command:  ttest Mod, by(Index) unequal
_pm_1:  r(mu_1)-r(mu_2)
permute var:  Mod

----------------------------------------------------------------------------
--
T            |     T(obs)       c       n   p=c/n   SE(p) [95% Conf.
Interval]
-------------+--------------------------------------------------------------
--
_pm_1 |  -.1266989       0     100  0.0000  0.0000         0
.0362167
----------------------------------------------------------------------------
--
Note:  Confidence interval is with respect to p=c/n.
Note:  c = #{|T| >= |T(obs)|}

-----Original Message-----
From: Carlo Lazzaro [mailto:carlo.lazzaro@tiscalinet.it]
Sent: Thursday, April 30, 2009 1:49 AM
To: statalist@hsphsun2.harvard.edu
Cc: Hugh Robinson
Subject: R: permute test statistic

Dear Hugh,
are you looking for something like this (please, see example below):

............................ begin example........................
. input Mod

Mod
1. 1.113924
2. 1.122969
3. 1.057594
4. 1.057594
5. 1.148739
6. .9890202
7. .7163003
8. .7857646
9. .7346777
10. .8520272
11. .8732744
12. .7147149
13. end

. g Index="Mod 1" in 1/6
(6 missing values generated)

. replace Index="Mod 2" in 7/12

. ttest Mod, by(Index) unequal

. permute Mod (r(mu_1)-r(mu_2)), reps(100) strata(Index) : ttest Mod,
by(Index) unequal
(running ttest on estimation sample)
............................ end example........................

HTH and Kind Regards,
Carlo
-----Messaggio originale-----
Da: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Per conto di Hugh Robinson
Inviato: giovedì 30 aprile 2009 4.09
A: statalist@hsphsun2.harvard.edu
Oggetto: st: permute test statistic

Can anyone tell me how to code permute properly to test if one modeled
growth rate (mod1) is greater than another (mod2).
Variations on the code below give me a perfect p-value each time.  It
seems that I have to substitute something else for "mean" to come up
with the proper test statistic?

permute  Mod1 mean=r(mean), reps(200) right nodots nodrop nowarn:
summarize Mod2

An example of the data is below.

Row	Mod1		Mod2
1	1.113924	.7163003
2	1.122969	.7857646
3	1.057594	.7346777
4	1.153763	.8520272
5	1.148739	.8732744
6	.9890202	.7147149
.
.
.
1000	1.193932	.9315556

Thanks,
HR

Hugh S Robinson Ph.D.
Postdoctoral Researcher
Wildlife Biology Program
College of Forestry and Conservation
University of Montana
Missoula, MT 59802
(406) 243-2931

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```