Difference between revisions of "Lab Manual:MSSD"

From SpanLabWiki
Jump to: navigation, search
(New page: MSSD is a calculation of noise similar to variance, however instead of variance from the mean, the variance is calculated from the previous time point. I wrote a script to calculate MSSD ...)
 
Line 6: Line 6:
  
  
<nowiki>
+
#! /bin/csh
#! /bin/csh
+
 
+
# created by djy 20081021 for FINRA
# created by djy 20081021 for FINRA
+
 
+
# this script will calcualte the MSSD for a block of data
# this script will calcualte the MSSD for a block of data
+
 
+
#DEFINE VARIABLES HERE
#DEFINE VARIABLES HERE
+
 
+
set data = normfBIAS+tlrc # this is your data file
set data = normfBIAS+tlrc # this is your data file
+
set output = bias_MSSD # this is the prefix of the output data
set output = bias_MSSD # this is the prefix of the output data
+
 
+
@ startTR = 0 # set this to the starting TR, usually 0 if you want to calculate MSSD from the very beginning
@ startTR = 0 # set this to the starting TR, usually 0 if you want to calculate MSSD from the very beginning
+
@ TRcount = 1010 # set this to the total TRs, if you want to model the entire block
@ TRcount = 1010 # set this to the total TRs, if you want to model the entire block
+
@ endTR = $TRcount - 1 #set this to the TR you want to end on.
@ endTR = $TRcount - 1 #set this to the TR you want to end on.
+
 
+
 
+
# The real meat starts here.
# The real meat starts here.
+
 
+
@ TRsum = $endTR - $startTR
@ TRsum = $endTR - $startTR
+
 
+
@ currentTR = $startTR + 1 # set the current TR for the loop to the start TR + 1.
@ currentTR = $startTR + 1 # set the current TR for the loop to the start TR + 1.
+
@ previousTR = $currentTR - 1
@ previousTR = $currentTR - 1
+
 
+
echo $currentTR # print which TR we are starting with
echo $currentTR # print which TR we are starting with
+
 
+
3dcalc -float -a $data'['$previousTR']' -b $data'['$currentTR']' -expr "(b-a) * (b-a)" -prefix 'tempsum_'$output  
3dcalc -float -a $data'['$previousTR']' -b $data'['$currentTR']' -expr "(b-a) * (b-a)" -prefix 'tempsum_'$output  
+
 
+
3dcalc -float -a 'tempsum_'$output+tlrc -expr 'a' -prefix 'prevtotalsum_'$output
3dcalc -float -a 'tempsum_'$output+tlrc -expr 'a' -prefix 'prevtotalsum_'$output
+
 
+
rm -f tempsum_${output}*
rm -f tempsum_${output}*
+
 
+
@ currentTR = $currentTR + 1
@ currentTR = $currentTR + 1
+
 
+
while ( $currentTR < $endTR + 1)
while ( $currentTR < $endTR + 1)
+
echo $currentTR
echo $currentTR
+
@ previousTR = $currentTR - 1
@ previousTR = $currentTR - 1
+
3dcalc -float -a $data'['${previousTR}']' -b $data'['$currentTR']' -expr '(b-a) * (b-a)' -prefix 'tempsum_'${output}
3dcalc -float -a $data'['${previousTR}']' -b $data'['$currentTR']' -expr '(b-a) * (b-a)' -prefix 'tempsum_'${output}
+
3dcalc -float -a 'tempsum_'$output'+tlrc' -b 'prevtotalsum_'$output'+tlrc' -expr 'a+b' -prefix 'newtotalsum_'${output}
3dcalc -float -a 'tempsum_'$output'+tlrc' -b 'prevtotalsum_'$output'+tlrc' -expr 'a+b' -prefix 'newtotalsum_'${output}
+
rm -f tempsum_${output}*
rm -f tempsum_${output}*
+
rm -f prevtotalsum_${output}*
rm -f prevtotalsum_${output}*
+
3dcalc -float -a 'newtotalsum_'$output'+tlrc' -expr 'a' -prefix 'prevtotalsum_'$output
3dcalc -float -a 'newtotalsum_'$output'+tlrc' -expr 'a' -prefix 'prevtotalsum_'$output
+
rm -f newtotalsum_${output}*
rm -f newtotalsum_${output}*
+
@ currentTR = $currentTR + 1
@ currentTR = $currentTR + 1
+
end
end
+
 
+
echo "total TR's for average = "$TRsum
echo "total TR's for average = "$TRsum
+
 
+
3dcalc -float -a 'prevtotalsum_'$output'+tlrc' -expr 'a/('$TRsum')' -prefix $output
3dcalc -float -a 'prevtotalsum_'$output'+tlrc' -expr 'a/('$TRsum')' -prefix $output
+
 
+
rm -f prevtotalsum_${output}*
rm -f prevtotalsum_${output}*
+
</nowiki>
+

Revision as of 15:27, 22 October 2008

MSSD is a calculation of noise similar to variance, however instead of variance from the mean, the variance is calculated from the previous time point.

I wrote a script to calculate MSSD in AFNI.

This script is useful if you want to do a whole brain analysis of MSSD across subjects.


#! /bin/csh

# created by djy 20081021 for FINRA

# this script will calcualte the MSSD for a block of data

#DEFINE VARIABLES HERE

set data = normfBIAS+tlrc # this is your data file
set output = bias_MSSD # this is the prefix of the output data

@ startTR = 0 # set this to the starting TR, usually 0 if you want to calculate MSSD from the very beginning
@ TRcount = 1010 # set this to the total TRs, if you want to model the entire block
@ endTR = $TRcount - 1 #set this to the TR you want to end on.


# The real meat starts here.

@ TRsum = $endTR - $startTR

@ currentTR = $startTR + 1 # set the current TR for the loop to the start TR + 1.
@ previousTR = $currentTR - 1

echo $currentTR # print which TR we are starting with

3dcalc -float -a $data'['$previousTR']' -b $data'['$currentTR']' -expr "(b-a) * (b-a)" -prefix 'tempsum_'$output 

3dcalc -float -a 'tempsum_'$output+tlrc -expr 'a' -prefix 'prevtotalsum_'$output

rm -f tempsum_${output}*

@ currentTR = $currentTR + 1

while ( $currentTR < $endTR + 1)
	echo $currentTR
	@ previousTR = $currentTR - 1
	3dcalc -float -a $data'['${previousTR}']' -b $data'['$currentTR']' -expr '(b-a) * (b-a)' -prefix 'tempsum_'${output}
	3dcalc -float -a 'tempsum_'$output'+tlrc' -b 'prevtotalsum_'$output'+tlrc' -expr 'a+b' -prefix 'newtotalsum_'${output}
	rm -f tempsum_${output}*
	rm -f prevtotalsum_${output}*
	3dcalc -float -a 'newtotalsum_'$output'+tlrc' -expr 'a' -prefix 'prevtotalsum_'$output
	rm -f newtotalsum_${output}*
	@ currentTR = $currentTR + 1
end

echo "total TR's for average = "$TRsum

3dcalc -float -a 'prevtotalsum_'$output'+tlrc' -expr 'a/('$TRsum')' -prefix $output

rm -f prevtotalsum_${output}*