Here's a paired-samples permutation test.  Note that this does not obtain a
p-value based on all possible randomization orders, a test that by some
nomenclatures would be called a Randomization test and which I presume is
what you desire given the use of the word "exact" in your query.
Instead, the permutation test below it merely reshuffles the data randomly
many times; for small data sets this may achieve all possible randomization
orders, but for larger data sets it will more likely achieve only a subset
of all possible randomization orders. In any case, employing a large number
of randomization orders (set the "iterations" variable to something like
1e5) should provide a good approximation to the exact p-value. You can
always run the test several times to ensure all results are approximately
equal.
pairperm <- function(data1,data2,iterations,tails){
obs_diff = data1-data2 #create a vector of the difference scores
sim_diff = rep(0,length(data1)) #create an empty vector to be filled later
flip = rep(0,length(data1)) #create an empty vector to be filled later
all_data = as.data.frame(cbind(obs_diff,sim_diff,flip)) #create a table with
your difference scores and empty vectors as columns
obs_mean_diff = mean(all_data$obs_diff) #measure the observed mean
difference score
count = 1 #initialize counting variable
for(i in 1:iterations){ #start shuffling loop
all_data$flip = sample(c(-1,1),length(data1), replace=T) #randomly assign
cases to be flipped or not
all_data$sim_diff=all_data$obs_diff*all_data$flip #this flips the sign of
those cases marked for flip
sim_mean_diff = mean(all_data$sim_diff) #calculate the simulated mean
difference score
if(tails == 1){ #if one-tailed
if(obs_mean_diff<sim_mean_diff){ #if the difference is more extreme in the
same direction from the null
count = count + 1
}
}
if(tails == 2){ #if two-tailed
if(abs(obs_mean_diff)<abs(sim_mean_diff)){ #if the difference is more
extreme in either direction from the null
count = count + 1
}
}
}
return(count/iterations) #return a p-value
}


On Mon, Dec 8, 2008 at 7:15 AM, LE PAPE Gilles <lepape.gilles@neuf.fr>wrote:

> I all,
> is there a way with R to perform an exact permutation test to replace the
> wilcoxon test to compare paired series and/or to perform pairwise multiple
> comparisons for related series after a Friedman test ?
> Thanks
> Gilles
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University
www.thatmike.com

Looking to arrange a meeting? Do so at:
http://www.timetomeet.info/with/mike/

~ Certainty is folly... I think. ~

	[[alternative HTML version deleted]]

