Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How can I bootstrap fMRI data? (specifics inside)

Subject: How can I bootstrap fMRI data? (specifics inside)

From: John

Date: 12 Jan, 2012 00:31:09

Message: 1 of 5

Greetings all,

I am trying to generate random samples from a set of fMRI data (brain imaging), which I would then subject to a series of custom programs that I've already built. While I was going to just use the bootstrp function, it says in the documentation that it randomly samples the rows of matrix data, which will not provide meaningful samples for my use. To be more clear:

I have already isolated the brain slices that I wish to use from each patient and put them in a single 640x3744 matrix. That's 16 patients top-to-bottom and 78 timed images of the 40x48 brains left-to-right.

I need a program (or directions for constructing a program) that will sample from these specific 40-row chunks (the rows of brain images), giving me a "new" sample of 16 patients (a "new 640x3744 matrix). If bootstrp can already do that, I'm afraid I can't quite figure out how.

If more detail is needed, I can provide it. I've hit a bit of a wall here, and need outside assistance. Thank you in advance for any responses.

Subject: How can I bootstrap fMRI data? (specifics inside)

From: Ashish Uthama

Date: 12 Jan, 2012 14:57:20

Message: 2 of 5

On Wed, 11 Jan 2012 19:31:09 -0500, John <jamesgalloway@windstream.net>
wrote:

> Greetings all,
>
> I am trying to generate random samples from a set of fMRI data (brain
> imaging), which I would then subject to a series of custom programs that
> I've already built. While I was going to just use the bootstrp function,
> it says in the documentation that it randomly samples the rows of matrix
> data, which will not provide meaningful samples for my use. To be more
> clear:
>
> I have already isolated the brain slices that I wish to use from each
> patient and put them in a single 640x3744 matrix. That's 16 patients
> top-to-bottom and 78 timed images of the 40x48 brains left-to-right.
>
> I need a program (or directions for constructing a program) that will
> sample from these specific 40-row chunks (the rows of brain images),
> giving me a "new" sample of 16 patients (a "new 640x3744 matrix). If
> bootstrp can already do that, I'm afraid I can't quite figure out how.
>
> If more detail is needed, I can provide it. I've hit a bit of a wall
> here, and need outside assistance. Thank you in advance for any
> responses.

Disclaimer: am not much of a stats person.

 From what I remember of bootstrapping, its a random reorder of the
existing data.
Here is one way to scramble all the slices.

This is NOT the most efficient or elegant, but I hope it is at least clear
on what it does :)


function sample = getARandomReorderedSample(originalData)

% test data (needs IPT)
% originalData = blockproc(ones(640,3744),[40 48],
@(bs)bs.data*prod(bs.location));
% imagesc(originalData);

%numPatients = 16;
slicew = 48;
sliceh = 40;
%T = 78;

% Row and column indices pointing to the start of each individual slice
sliceStart_rvec = 1:sliceh: size(originalData,1);
sliceStart_cvec = 1:slicew: size(originalData,2);

% Create two 78x16 matrices holding the starting point in corresponding
% locations to each of the individual slices
[sliceStart_rs, sliceStart_cs] = meshgrid(sliceStart_rvec,
sliceStart_cvec);

% Create a random order of these slices
newOrder = randperm(numel(sliceStart_rs));

% preallocate
sample = zeros(size(originalData));
% Reorder the data
sliceNum = 1;
for cInd = sliceStart_cvec
     for rInd = sliceStart_rvec

         randomSourceSliceNumber = newOrder(sliceNum);
         srcCInd = sliceStart_cs(randomSourceSliceNumber);
         srcRInd = sliceStart_rs(randomSourceSliceNumber);

         sample(rInd:(rInd+sliceh-1), cInd:(cInd+slicew-1)) = ...
             originalData(srcRInd:(srcRInd+sliceh-1),
srcCInd:(srcCInd+slicew-1));

         sliceNum = sliceNum + 1;
     end
end

% test
% imagesc(sample);

Subject: How can I bootstrap fMRI data? (specifics inside)

From: John

Date: 12 Jan, 2012 19:29:08

Message: 3 of 5

"Ashish Uthama" <first.last@mathworks.com> wrote in message <op.v7y7tubga5ziv5@authama-deb6-64.dhcp.mathworks.com>...
> Disclaimer: am not much of a stats person.
>
> From what I remember of bootstrapping, its a random reorder of the
> existing data.
> Here is one way to scramble all the slices.
>
> This is NOT the most efficient or elegant, but I hope it is at least clear
> on what it does :)
>
>
> function sample = getARandomReorderedSample(originalData)
>
> % test data (needs IPT)
> % originalData = blockproc(ones(640,3744),[40 48],
> @(bs)bs.data*prod(bs.location));
> % imagesc(originalData);
>
> %numPatients = 16;
> slicew = 48;
> sliceh = 40;
> %T = 78;
>
> % Row and column indices pointing to the start of each individual slice
> sliceStart_rvec = 1:sliceh: size(originalData,1);
> sliceStart_cvec = 1:slicew: size(originalData,2);
>
> % Create two 78x16 matrices holding the starting point in corresponding
> % locations to each of the individual slices
> [sliceStart_rs, sliceStart_cs] = meshgrid(sliceStart_rvec,
> sliceStart_cvec);
>
> % Create a random order of these slices
> newOrder = randperm(numel(sliceStart_rs));
>
> % preallocate
> sample = zeros(size(originalData));
> % Reorder the data
> sliceNum = 1;
> for cInd = sliceStart_cvec
> for rInd = sliceStart_rvec
>
> randomSourceSliceNumber = newOrder(sliceNum);
> srcCInd = sliceStart_cs(randomSourceSliceNumber);
> srcRInd = sliceStart_rs(randomSourceSliceNumber);
>
> sample(rInd:(rInd+sliceh-1), cInd:(cInd+slicew-1)) = ...
> originalData(srcRInd:(srcRInd+sliceh-1),
> srcCInd:(srcCInd+slicew-1));
>
> sliceNum = sliceNum + 1;
> end
> end
>
> % test
> % imagesc(sample);

Thank you, but I'm afraid I miscommunicated my desire. I wish to draw a sample of 16 40-row "chunks". As in, each unit of the "new" sample will be a 40x3744 block. I hate to ask this after you've done so much, but how would I modify your code to achieve this? Would I just change sliceh to 3744 and the two 78x16 matrices to two 1x16 vectors?

Subject: How can I bootstrap fMRI data? (specifics inside)

From: Ashish Uthama

Date: 13 Jan, 2012 14:42:21

Message: 4 of 5

On Thu, 12 Jan 2012 14:29:08 -0500, John <jamesgalloway@windstream.net>
wrote:

> "Ashish Uthama" <first.last@mathworks.com> wrote in message
> <op.v7y7tubga5ziv5@authama-deb6-64.dhcp.mathworks.com>...
>> Disclaimer: am not much of a stats person.
>> From what I remember of bootstrapping, its a random reorder of the
>> existing data.
>> Here is one way to scramble all the slices.
>> This is NOT the most efficient or elegant, but I hope it is at least
>> clear on what it does :)
>> function sample = getARandomReorderedSample(originalData)
>> % test data (needs IPT)
>> % originalData = blockproc(ones(640,3744),[40 48],
>> @(bs)bs.data*prod(bs.location));
>> % imagesc(originalData);
>> %numPatients = 16;
>> slicew = 48;
>> sliceh = 40;
>> %T = 78;
>> % Row and column indices pointing to the start of each individual slice
>> sliceStart_rvec = 1:sliceh: size(originalData,1);
>> sliceStart_cvec = 1:slicew: size(originalData,2);
>> % Create two 78x16 matrices holding the starting point in corresponding
>> % locations to each of the individual slices
>> [sliceStart_rs, sliceStart_cs] = meshgrid(sliceStart_rvec,
>> sliceStart_cvec);
>> % Create a random order of these slices
>> newOrder = randperm(numel(sliceStart_rs));
>> % preallocate
>> sample = zeros(size(originalData));
>> % Reorder the data
>> sliceNum = 1;
>> for cInd = sliceStart_cvec
>> for rInd = sliceStart_rvec
>> randomSourceSliceNumber = newOrder(sliceNum);
>> srcCInd = sliceStart_cs(randomSourceSliceNumber);
>> srcRInd = sliceStart_rs(randomSourceSliceNumber);
>> sample(rInd:(rInd+sliceh-1), cInd:(cInd+slicew-1)) = ...
>> originalData(srcRInd:(srcRInd+sliceh-1),
>> srcCInd:(srcCInd+slicew-1));
>> sliceNum = sliceNum + 1;
>> end
>> end
>> % test
>> % imagesc(sample);
>
> Thank you, but I'm afraid I miscommunicated my desire. I wish to draw a
> sample of 16 40-row "chunks". As in, each unit of the "new" sample will
> be a 40x3744 block. I hate to ask this after you've done so much, but
> how would I modify your code to achieve this? Would I just change sliceh
> to 3744 and the two 78x16 matrices to two 1x16 vectors?

You can use the same logic above,
Air code:

origData = rand(640,3744);

%get all the starting top-left indices of your chunks:
srcChunks = 1:40:640

%get a random order of 16 indices
newOrder = randperm(16)

%New start indices: This is the key. Make sure you understand this step
(it is using one matrix as a look-up indices inside another...)
dstChunks = srcChunks(newOrder)

%pre-allocate
sample = zeros(size(origData));

%reassemble data:
for chunkInd=1:16
   src = srcChunks(chunkInd);
   dst = dstChunks(chunkInd);

   sample(dst:dst+39,:) = origData(src:src+39,:)

end

Post back is any of the steps arent clear.

Subject: How can I bootstrap fMRI data? (specifics inside)

From: John

Date: 17 Jan, 2012 04:04:08

Message: 5 of 5

"Ashish Uthama" <first.last@mathworks.com> wrote in message <op.v701svjua5ziv5@authama-deb6-64.dhcp.mathworks.com>...
> You can use the same logic above,
> Air code:
>
> origData = rand(640,3744);
>
> %get all the starting top-left indices of your chunks:
> srcChunks = 1:40:640
>
> %get a random order of 16 indices
> newOrder = randperm(16)
>
> %New start indices: This is the key. Make sure you understand this step
> (it is using one matrix as a look-up indices inside another...)
> dstChunks = srcChunks(newOrder)
>
> %pre-allocate
> sample = zeros(size(origData));
>
> %reassemble data:
> for chunkInd=1:16
> src = srcChunks(chunkInd);
> dst = dstChunks(chunkInd);
>
> sample(dst:dst+39,:) = origData(src:src+39,:)
>
> end
>
> Post back is any of the steps arent clear.

Thank you ever so much! I had to slightly modify it to resample with replacement, but other than that it worked perfectly. You've been so helpful. I've got another big step that needs to be done with these data, but I can't ask you for any more after you've done so much.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us