Z Score Documentation z.scr

advertisement
Z Score Documentation
The z-score program in the file z.scr is loaded by the Summary program (menu option 14). The
z-score program that follows combines the routines for the z-scores analysis using the Thompson et al.
(1976) description, with the program for doing block z-scores analysis (originally the file called z.blk). The
difference between the two routines is that the former uses all the trials to calculate the preCS mean and
standard deviation that is used in the z-score calculation, whereas the latter only uses the trials on a blockby-block basis. The Thompson type analysis is used when the entire training session is the same (e.g., a
session of acquisition training) and is helpful when trying to identify changes in baseline activity from block
to block. The block analysis is used when there are blocks of normal training that need to be compared
with some manipulation, for example drug or cooling. The Thompson type analysis is started with
run<return> and the block analysis is started with blkrun<return>.
An additional feature of our implementation of the z-score analysis is that it uses the z-scores to
identify trials with significant activity in the CS period (epochs 2 and 3) on paired trials and significant
activity in the CS and US periods on tone-alone test trials (epochs 2, 3, 4, 5 and 6). By identifying
conditioned responses, trials to criterion can be calculated based on significant z-scores. Because eyelid
and unit activity are treated the same, trials to criterion can be calculated for either measure. Trials to
criterion are commonly calculated for behavioral activity, but this is one of the few instances where trials to
criterion can be calculated on the basis of unit activity.
As with the other programs in these appendices, this file has been modified in the following ways:
comments have been expanded; screens have been idenfified by numbers; codes and comments used
for debugging have been removed to avoid confusion (for example, we have edited out all the double
number routines); screens have been combined when their separation served no compilation or
documentary purpose; and for documentation, some additional screens concerning parameters, epochs
and instructions have been included as comments.
\ screen 0
\ Z.BLK file
\
\ this program computes z-scores.
\ this program saves Ex for every trial in AUX (segment 3) as floating point numbers
\ (these are averages sums, not sums).
\
\ RAM DROP temporarily stores block and session information;
\ PAD could be used instead.
\
\ trial type 1 = CS alone, 2 = CS/UCS, 3 = UCS alone.
\
\ USE: RUN (all trial types) or BLKRUN (only paired trials)
\
\ REM critical z values:
\ one-tailed: 0.05, 1.65; 0.01, 2.32.
\ two-tailed: 0.05, 1.96; 0.01, 2.58.
\
\ Z.ORG contains the original z-score program.
\ Z.DBL holds a version that uses both dbl and flt pt AUX.
\ Z.FLT is the basic version used for Z.SCR and Z.BLK.
\ Z.BLK does independent block z scores also.
\ screen 1
\ this screen controls all loading of the z-score routines.
NEED ZSCORES
NOT
\if forget zscores
NEED FLOAT
\if reloading float
\ Micromotion MasterForth's floating point does not include the following definitions ...
NEED FSQR
\if : fsqr ( fn -- fn2) fdup f* ;
NEED F<=
\if : f<= ( f1 f2--t/f) fover fover f< >r f= r> or ;
decimal
create zscores
create z.blk
NEED D#BYTES
\if 4 constant d#bytes
\ 2 load
\ 3 load
4 size 2- thru
\ size 1- load
\ parameters documentation.
\ ranges documentation.
\ major program.
\ instruction documentation.
decimal
\ roadrunner
\ screen 2
\ parameter documentation.
\ this information or information like it is loaded by the Summary program and is needed for
\ using the z-score program.
\
\ 1 #a/d !
\ number of a/d channels.
\ 2 #units !
\ 4000 bin !
\ 252 scale toneon
\ 252 2* scale shkon \ shkon 2- is shkon
\ 252 3 * scale pts
\ 3 types !
\ 108 #t/blk !
\ 1 #blks !
\ 108 #trls !
\ 7 bada/d !
\ 100 badunits !
\ 25 badtime !
\ printing off
\ number of unit channels.
\ binwidth in microseconds.
\ tone onset.
\ shock onset.
\ length of trial; number of data points per channel.
\ number of trial types (CS, US and CS+US).
\ number of trials per block.
\ number of blocks.
\ number of trials.
\ a/d criterion for bad trials (7 = 0.7 mm).
\ unit criterion for bad trials.
\ bad trial if movement in first 25 ms of CS period.
\ off = print to monitor only.
\ screen 3
\ ranges documentation.
\ this information or information like it is found on screens 10 and 11 of the summary.scr file.
\ it is duplicated here for documentation purposes.
\
\ variable #periods
\ number of epochs in preCS period.
\
\ : 2nd ( -- n)
\ \ n is the number of bins in half of the preCS period.
\
2 #periods !
\
toneon 2 / ;
\
\ : 3rd ( -- n)
\ \ n is the number of bins in a third of the preCS period.
\
3 #periods !
\
toneon 3 / ;
\
\ : 4th ( -- n)
\ \ n is the number of bins in a fourth of the preCS period.
\
4 #periods !
\
toneon 4 / ;
\
\ create ranges 0 , 0 , ( will hold #ranges = ranges @ )
\ \ the following values are ranges in terms of bins.
\ \ using calculations and definitions for 2nd, 3rd and 4th helps make certain the differences for each
\ \ range are the same.
\
here ( n)
\
toneon
dup 3rd - swap , ,
\ could be any third of preCS period.
\ here, PCS epoch number 3 out of 3 is
\ used for mean and standard deviation.
\
\
shkon 3rd - 3rd dup 3rd - swap , ,
\ could be any nonoverlapping epoch in
\ the trial.
\ here, CS epoch number 1 out of 3.
\
shkon 3rd dup 3rd - swap , ,
\ ditto; here CS epoch number 2 of 3.
\
shkon
dup 3rd - swap , ,
\ ditto; here CS epoch number 3 of 3.
\
shkon
dup 3rd +
,,
\ ditto; here US epoch number 1 of 3.
\
shkon 3rd +
dup 3rd +
,,
\ ditto; here US epoch number 2 of 3.
\
shkon 3rd + 3rd +
dup 3rd +
,,
\ ditto; here US epoch number 3 of 3.
\
( n) here swap - d#bytes u/ ranges !
\ store numbe of ranges; here, 7.
\ screen 4
\ display ranges.
variable range#
: 'range ( n -- adr)
\ given index number, return address of table corresponding to that range number.
d#bytes * ranges + ;
: .ranges ( --)
\ print table of range values.
1 ( fr) ranges @ ( #) bounds
?do
." No. " i 0 2 d.r i 'range 2@ 1- swap
bin @ 1000 / * 0 5 d.r ." -"
bin @ 1000 / * 0 5 d.r ." msec inclusive"
i 'range 2@ 1- swap
." ( bins " 0 3 d.r ." - " 0 3 d.r ." )" cr
loop ;
\ screen 5
\ printing controls.
variable amount
: long ( --)
\ print long form of data output.
amount on ;
: short ( --)
\ print short form of data output.
amount off ;
\ Epson printer ...
\ : +CONDENSED ( --) 15 EMIT ;
\ : -CONDENSED ( --) 18 EMIT ;
\ HP Laserjet printer ...
: +CONDENSED ( --)
\ use condensed printing.
esc# emit " (s16.66h8.5v0T" type ;
: -CONDENSED ( --)
\ use normal printing.
esc# emit " (s12h10v3T" type ;
\ screen 6
\ trials array
variable data#
\ first data, second, etc.; 0 to n-1.
\ used to pass index.
: trials ( row col -- dadr.l)
\ given row and column, return long address for double number value.
\ use: 1,1 to row,col = dn.
\ REM: 0 <= data# @ <= #a/d @ #units @ +.
1- f#bytes * ( col')
swap 1- data# @ #trls @ * + ranges @ * f#bytes * ( row')
+ ( col' + row') 12288 ( =$3000, segment 3) ;
\ identities ...
: f@l ( offset segment -- fn)
\ equivalent long floating point fetch.
2@l ;
: f!l ( offset seqment fn --)
\ equivalent long floating point store.
2!l ;
\ screen 7
\ trial collection
: calcmeas ( --)
\ calculate measures (preCS/CS/US amplitude/area/latency) for trial.
\ borrowed from the Summary program, this is needed to calculate bad trials.
trl# @ ( i)
clearpointers
dup ( i i) block allocate
nmrv (nmrv) max#a/d 2* cmove
unitv (unitv) max#units 2* cmove
measure
( i) trial>aux ;
\ screen 8
\ calculate sum of x for all ranges and store in auxilliary memory for a single trial.
: into ( -- n)
\ given an index (data#), get address of trial data.
data# @ pts * trl# @ block + ;
: collect ( --)
\ sum ranges within trial then store in AUX.
\ this routine operates to sum all ranges (using range table) for a single trial.
\ assumes trl# (1 to n) is set.
\ note: data# is used to pass index parameter here and in trials.
0 ( fr) #a/d @ #units @ + ( #) bounds
?do
i data# ! 1 ( fr) ranges @ ( #) bounds
?do
0 0 ( Ex dummy)
i 'range 2@ into + swap into +
?do
i c@ 0 d+
loop
( dEx) float ( fEx) \ convert double number to floating point number for storage.
trl# @ ( row) i ( col) trials f!l
nuf? ?leave
loop
loop
calcmeas ;
\ screen 9
\ process every trial.
: bytrials ( --)
\ read every trial and do calculations.
0 block 64 + 0 64 >a ( move header to aux)
ram erase
dark
." Initial processing of data"
cr ." Processing trial "
1 #trls @ bounds
?do
i trl# !
17 1 at i 0 3 d.r \ print trial number
collect
nuf? ?leave
loop ;
variable cell
9 cell !
: .rw ( trial1 trial2 --)
\ print raw trial data by range.
?do
i 0 3 d.r space i 1- ttarr + c@ emit
3 spaces
1 ( fr) ranges @ ( #) bounds
?do
j i trials f@l 0 cell @ f.r
loop
cr
nuf? ?leave
loop ;
\ screen 10
\
continued
: .raw ( --)
\ print raw trial data for all trials.
0 ( fr) #a/d @ #units @ + ( #) bounds
?do
i data# !
cr ." Data number " i 1+ 0 3 d.r
cr cr
1 ( fr) #trls @ ( #) bounds .rw
loop
cr ;
\ screen 11
\ arrays and fvariables
: array ( range# @ 1- -- adr)
\ use RAM as temporary array space.
f#bytes * ram drop + ;
: room ( --)
\ check to make sure there is enough room in RAM to analyze the amount of data requested.
#trls @ ranges @ * #a/d @ #units @ + * ( room for trials)
65535 u< not abort" Not enough room in AUXILLIARY"
ranges @ f#bytes * 1 ( # temp buffers, see array) *
ram nip u< not
abort" Not enough room in RAM" ;
\ floating point variables for z-score calculations ...
\ "general" refers to epoch (usually preCS) used to calculate mean and standard error used for
\
z-scores.
fvariable fn
fvariable fEx
fvariable fEx2
fvariable fEx2block
fvariable fmean
fvariable fdev
\ general n (number) of periods.
\ general Ex (sum of x) of periods.
\ general Ex2 (sum of squared x's) of periods.
\ Ex2 (sum of squared x's) of block.
\ general mean of periods.
\ general standard deviation of periods.
\ screen 12
\ initialize
: initialize ( --)
\ zero all cumulators before calculations.
0. float fn f!
0. float fEx f!
0. float fEx2 f!
0. float fEx2block f!
0 array ( fr) ranges @ 1+ f#bytes * 1+ ( #) erase ;
: f+! ( fvar adr --)
\ floating point equivalent to +!
dup >r f@ f+ r> f! ;
: .flt ( adr n --)
\ print floating point number.
>r f@ r> cell @ f.r ;
: .grand ( --)
\ print grand statistics.
." Data #" data# @ 1+ 0 3 d.r ." over all trial types"
cr ." Period Grand N = " fn 0 .flt
cr ." Period Grand Ex = " fEx 0 .flt
cr ." Period Grand Ex2 = " fEx2 0 .flt
cr ." Period Grand Mean = " fmean 2 .flt
cr ." Bin Grand Mean = " fmean f@ toneon #periods @ /
0 float f/ 2 cell @ f.r
cr ." Period Grand Dev = " fdev f@ f0=
if
7 spaces ." ??"
else
fdev 2 .flt
then
cr ;
\ screen 13
\ grand statistics: mean, deviation
: gmean ( --)
\ grand mean.
fEx f@ fn f@ f/ fmean f! ;
: gdeviation ( --)
\ grand standard deviation.
\ population sigma = [ E(x - mean)**2 / N ] ** 1/2
\ sample ( N < 30) sigma =
\ [ [ Ex**2 - [ (Ex)**2 / N ] ] / ( N - 1) ] ** 1/2
fEx2 f@ fEx f@ fsqr fn f@ f/ f- ( numerator)
fn f@ fdup 30. float f< fn f@ 2. float f- f0< not and
if 1. float f- then ( denominator)
f/ fsqrt fdev f! ;
\ screen 14
\ pcs calculations ...
: +pcs ( --)
\ add in trial from AUX.
1. float ( fvalue) fn ( fvariable) f+!
trl# @ 1 trials f@l fdup fEx f+!
fsqr fEx2 f+! ;
: pcs ( fr # --)
\ preCS calculations.
\ must set data# for trials.
initialize
bounds
?do
i 1- bdtarr + c@ 0= ( true if good trial)
if i trl# ! +pcs then
loop
gmean
gdeviation ;
\ screen 15
\ print trials ...
: .float ( fvalue n --)
\ print floating point number.
cell @ f.r ;
: .trl ( trial1 trial2 --)
\ print raw trial data.
?do
i 1- bdtarr + c@
if
ascii - emit
else
i 1- crtarr + c@
if
ascii + emit
else
space
then
then
i 0 3 d.r space i 1- ttarr + c@ emit
3 spaces
1 ( fr) ranges @ ( #) bounds
?do
j i trials f@l i 1 =
if
fmean f@
else
j 1 trials f@l
then
f- fdev f@ f/ 2 .float
loop
cr
nuf? ?leave
loop ;
\ screen 16
\
continued
: .trials ( --)
\ print all trials.
1 ( fr) #trls @ ( #) bounds .trl ;
\ screen 17
\ trial words
: +trial ( --)
\ add in trial from AUX.
1. float ( fvalue) fn ( fvariable) f+!
1 ( fr) ranges @ ( #) bounds
?do
i range# !
trl# @ range# @ trials f@l range# @ 1 =
if
fdup fsqr fEx2block f+!
then
range# @ array f+!
loop ;
: *trials ( fr # --)
\ for a range of trials add in good trials.
\ must set data# and trltype.
bounds
?do
i trl# !
i 1- bdtarr + c@ 0= ( true if good trial)
trl# @ 1- ttarr + c@ ascii 1 - trltype @ = ( correct?)
and
if +trial then
loop ;
\ screen 18
\ calculater percent
: calc% ( fr to --)
\ calculate percent.
\ use after figurebadtrials & figurecrtrials.
bounds 0 ( sum) 0 ( n) 2swap
?do
ttarr i 1- + c@ ascii 1 - trltype @ =
if
bdtarr i 1- + c@ 0=
if
1+ crtarr i 1- + c@
if
swap 1+ swap
then
then
then
loop
2dup
>r 1000 um* r> rm/ .tenths ." %"
space ascii ( emit swap u. ascii / emit u. ascii ) emit ;
: sescalc% ( --)
\ calculate session percentages.
0 types @ bounds
?do
i trltype !
." CRs for trial type " trltype @ 1+ u. ." :"
1 ( fr) #trls @ ( #) calc% cr
loop ;
\ screen 19
\
continued
: .. ( i --)
\ print N, Ex; calc & print Mean & Z.
0 3 d.r
." N =" fn f@ 0 ( decimals) 4 ( field) f.r cr
1 ( fr) ranges @ ( #) bounds ( dn)
amount @
if
3 spaces
." Ex = " 2dup
?do
i array f@ 0 .float
loop
cr
3 spaces
." Mean = " 2dup
?do
i array f@ fn f@ f/ 2 .float
loop
cr
then ( dn)
3 spaces
." Z = "
?do
i array f@ fn f@ f/ i 1 =
if
fmean f@
else
1 array f@ fn f@ f/
then
f- fdev f@ f/ 2 .float
loop
cr ;
\ screen 20
\ messages
: .warning ( --)
\ print warning.
data# @ #a/d @ u<
if
." WARNING: The program believes that this is NM data."
cr
." Because of the way a/d data is stored, if this is a/d data then multiply z-scores by -1 to
change the sign"
cr
then ;
: .comment ( --)
\ print comment.
0 info 64 a> info 64 -trailing type
cr ;
: .headings ( --)
\ print headings.
." Data #"
data# @ 1+ 0 3 d.r
cr
." Trial Type #" trltype @ 1+ 0 3 d.r
cr ;
: straiten ( str cell --)
\ straighten (right justify) field for printing.
2dup swap - 0<
if
swap over min swap
then
over - spaces type ;
: .fields ( --)
\ print fields.
." Blk stats " 1 ( fr) ranges @ ( #) bounds
?do
" No." cell @ 2- straiten i 0 2 d.r
loop
cr ;
: likepage ( --)
\ on monitor, print a line of periods to indicate page break.
cr 70 0
do
ascii . emit
loop
cr ;
: page? ( --)
\ at page break, act according to printer or monitor.
printing @
if
page
else
likepage
then ;
\ screen 21
\ z-criteria
variable zcrit 165 zcrit !
fvariable fcrit
\ integer z-critical; user friendly
\ floating point of zcrit divided by 100.
: zcr ( --) 2 ( fr)
\ determine CR by using z-score.
ttarr trl# @ 1- + c@ ascii 1 =
if
ranges @ 1- ( CS)
else
#periods @ ( paired)
then ( #)
bounds
?do
fdev f@ f0= not
if
fcrit f@
trl# @ i trials f@l
trl# @ 1 trials f@l ( instead of fmean f@)
f- fdev f@ f/ ( z)
data# @ #a/d @ u< ( true if a/d) if fnegate then f<=
if
1 crtarr trl# @ 1- + c!
then
then
loop ;
\ screen 22
\
continued
' nm/unflag is badflag
\ false, nmflag, unflag, nm/unflag
: figurebadtrials ( --)
\ figure out which trials are bad.
\ do this routine before using pcs routine.
bdtarr #trls @ erase
1 ( fr) #trls @ ( #) bounds
?do
i trl# ! ttarr i 1- + c@ ascii 1 - ( converts ascii)
trltype ! ( used by walk)
movedata
badflag
if
1 bdtarr trl# @ 1- + c!
then
loop ;
: figurecrtrials ( fr # --)
\ figure out which trials have a conditioned response.
\ do this routine after pcs routine & before .trials routine.
crtarr #trls @ erase
bounds
?do
i trl# ! ttarr i 1- + c@ ascii 1 - ( converts ascii)
trltype ! ( used by walk)
movedata
badflag not
if zcr then
loop ;
\ screen 23
\ run
: .rn ( --)
\ print run.
1 ( fr) #blks @ ( #) bounds
?do
initialize
i 1- #t/blk @ * 1+ ( fr) #t/blk @ ( #) *trials
i .. space
i 1- #t/blk @ * 1+ ( fr) #t/blk @ ( #) calc%
cr
nuf? ?leave
loop ;
\ screen 24
\
continued
: .zcrit ( --)
\ print z-score criteria.
." Z-score critical level set at " fcrit f@
data# @ #a/d @ u<
if
fnegate f. ." and below"
else
f. ." and above"
then
cr ;
\ ' noop is .criteria
\ .nmlevel, .unlevel
' .zcrit is .criteria
\ screen 25
\ load these routines if need new .bad and .good for printing.
\ the following limits length of line for printing trials.
need items \| ( beginning of conditional compiling ...)
var items 25 items !
: ret ( n i -- n')
u. space 1+ dup items @ mod 0= if cr then ;
: .BAD ( --)
\ print bad trials.
CR
." BAD TRIALS: "
0
1 ( fr) #TRLS @ ( #) BOUNDS
DO
BDTARR I 1- + C@ 0<>
IF
I ret
THEN
LOOP
drop
CR ;
: .GOOD ( --)
\ print good trials.
CR
." CR TRIALS: "
0
1 ( fr) #TRLS @ ( #) BOUNDS
DO
CRTARR I 1- + C@ 0<>
IF
I ret
THEN
LOOP
drop
CR CR ;
| ( ... end of conditional compiling)
: ... ( i --)
\ new print out word for block z-scores.
\ print N, Ex; calc & print Mean & Z.
." Block =" 1+ 0 3 d.r
." N =" fn f@ 0 ( decimals) 4 ( field) f.r
cr
1 ( fr) ranges @ ( #) bounds ( dn)
amount @
if
3 spaces
." Ex = " 2dup
?do
i array f@ 0 .float
loop
cr
3 spaces
." Mean = " 2dup
?do
i array f@ fn f@ f/ 2 .float
loop
cr
then ( dn)
3 spaces
." Z = "
?do
i array f@ fn f@ f/
1 array f@ fn f@ f/ f- fdev f@ f/ 2 .float
loop
cr ;
\ screen 26
\ runblocks
: runblocks ( --)
\ print block z scores.
\ debugging notes:
\
room debug @ not if bytrials then
\
zcrit @ 0 float 100. float f/ fcrit f!
\
zcrit intgr to float.
\
figurebadtrials
\
printing @ if printer on +condensed then
0 ( fr) #a/d @ #units @ + ( #) bounds
?do
i data# !
0 ( fr) types @ ( #) bounds
?do
i trltype !
.comment
cr .headings cr
0 ( fr) #blks @ ( #) bounds
?do
#blks @ #trls @ <>
if
initialize
i #t/blk @ * 1+ ( fr) #t/blk @ ( #) *trials
1 array f@ fEx f! fEx2block f@ fEx2 f!
gmean
gdeviation
\
.grand ( debug)
i ...
else
." Warning: Use RUN instead for this analysis"
then
nuf? ?leave
loop
page?
loop
key? if key esc# = if abort then then
loop ;
\ printing @ if -condensed printer off then ;
\ screen 27
\
continued
: run ( --)
\ this is the main execution word for z-score analysis of normal trials.
room
debug @ not if bytrials then
zcrit @ 0 float 100. float f/ fcrit f!
\ zcrit intgr to float.
figurebadtrials
printing @
if
printer on +condensed
then
0 ( fr) #a/d @ #units @ + ( #) bounds
?do
i data# !
.comment
cr
.ranges
cr
1 ( fr) #trls @ ( #) pcs .grand
cr
1 ( fr) #trls @ ( #) figurecrtrials
key? if key esc# = if abort then then
.
warning
.bad
.good
criterion
sescalc%
cr
#blks @ #trls @ <>
if
0 ( fr) types @ ( #) bounds
?do
i trltype !
.headings cr
.fields cr
.rn cr
loop
page?
else
.fields cr
.trials
page?
then
loop
runblocks
printing @
if
printer off
then ;
\ screen 28
\
continued
: blkrun ( --)
\ execution word for normal block analysis for z-scores.
\ analyze paired in blocks only.
room
bytrials
zcrit @ 0 float 100. float f/ fcrit f!
figurebadtrials
printing @
if
printer on
+condensed
then
#a/d @ #units @ + 0
?do
i data# !
0 ( fr) types @ ( #) bounds
?do
i trltype !
i 1 = ( variability only in paired trials in block)
if
.comment cr
.headings cr
0 #blks @ bounds
?do
#blks @ #trls @ <>
if
initialize
i #t/blk @ * 1+ ( fr) #t/blk @ ( #) *trials
1 array f@ fEx f! fEx2block f@ fEx2 f!
gmean
gdeviation
i ...
else
." Use RUN for this analysis"
then
nuf? ?leave
loop
page?
then
loop
key? if key esc# = if abort then then
loop
printing @
if
printer off
then ;
\ screen 29
\ documentation instructions (screen 11 of summary.scr)
\
\ Instructions:
\ Make certain the differences for each range are the same.
\
\ \ including z.scr
\ original Thompson et al. 1976 z-score analysis
\
\ including z.blk
\ original and analysis for zscores by block
\ short
\
\ the following are typical instructions for using this analysis ...
\
\ Type the following ...
\
flush <return>
\
printing on <return>
\
long<return>
(all statistics in print out; rarely used, mostly for debugging)
\
or short<return>
(minimal statistics in print out; default and usual choice)
\
1 #a/d !<return>
(for example)
\
1 #units !<return>
(for example)
\
using filename.sc <return>
(i.e., open a data file)
\
run <return>
(Thompson z-score analysis)
\
or blkrun<return>
(block z-score analysis, e.g., drug or cooling)
\
\ these commands can be repeated as often as desired without reloading program.
\
Download