Skip to content

Random Relabelling

11 messages · kmatthews, Kevin Matthews, Jeremy Hetzel +4 more

#
Can you explain this a bit more. At the moment I don't see what you are trying to achieve.   "calculate the mean of the 1000 values at each of the 4000 points" does not seem to make sense.
--- On Wed, 4/20/11, kmatthews <kevin-matthews at uiowa.edu> wrote:

            
#
Kevin,

The following follows John's suggestion, but without the loop.  It's quick 
for me.

Jeremy


Jeremy T. Hetzel
Boston University



## Generate sample data
n <- 4000
rep <- 1000
rate <- rnorm(n, mean = 15, sd = 2) / 100000 # Mortality rates around 
15/100k

## Create an empty matrix with appropriate dimensions
permutations <- matrix(ncol = n, nrow = rep)

## Use apply() to resample
permutations <- apply(permutations, 1, function(x)
{
sample(rate, size = n, replace = F)
})

## Look at the matrix
dim(permutations)
head(permutations)

## Find the column means
means <- apply(permutations, 1, mean)
means
On Wednesday, April 20, 2011 1:56:35 PM UTC-4, John Kane wrote:
#
Hi:

How about

y <- rnorm(4000)
ymat <- rowMeans(replicate(1000, y[sample(4000)]))
hist(ymeans)

system.time({y <- rnorm(4000); yy <- rowMeans(replicate(1000,
y[sample(4000)]))})
   user  system elapsed
   0.19    0.03    0.22

HTH,
Dennis
On Wed, Apr 20, 2011 at 7:04 AM, kmatthews <kevin-matthews at uiowa.edu> wrote:
2 days later
#
I KNEW there was a better way!
--- On Wed, 4/20/11, Jeremy Hetzel <jthetzel at gmail.com> wrote:

            
#
On 2011-04-23 03:42, John Kane wrote:
And you might note that

  means <- rowMeansy(permutations)

is about 10-15 times faster (if speed matters).

Peter Ehlers

[...snipped...]
2 days later
#
On Apr 25, 2011, at 10:53 AM, kmatthews wrote:

            
The practice varies, some people do appreciate it. Doing so when one  
is not subscribed, however, adds many additional mouse-maneuvers to  
the moderator workload, ...  wasted time in my opinion. I would  
suggest a private thank you message in that instance (or even more to  
be preferred ... subscribing.)
#
--- On Mon, 4/25/11, kmatthews <kevin-matthews at uiowa.edu> wrote:

            
Certainly and thanks