Payoff Matrix - Feedback Counter (Tidy up script)
David McFarlane
mcfarla9 at msu.edu
Mon Jan 10 19:32:47 UTC 2011
Caleb,
I commend you for taking an interest in improving your code, instead
of simply settling for the first bit of code that gives the appearnce
of working (and which almost always fails on close inspection). I
hope my comments below don't seem too harsh, if so just consider that
they come from a grouchy old man.
First, some style issues -- Your code appeared in my e-mail reader
with indentations of *12* spaces! That is *way* too much
indentation, it makes the code quickly run off the edge of the screen
and makes it unreadable. Please learn to use the well-documented
industry standard indentation of 4 spaces. Also, *please* resist the
urge to double-space your code, that only reduces how much of your
code will fit into view on my screen and does nothing to aid
understanding. I had to take your code into my own text editor and
edit it down to make it readable, do not expect me to do that again.
Now, a few comments on the code itself. First, I wonder if you
really need two different Slide objects? If they perform essentially
the same function only with different content, then I would just use
one Slide and change the content using attribute references. That
could simplify the code right there.
Next, ignoring the MsgBox statements, it seems to me that all that
changes in the various conditions is the number of points by which
AccuracyDisplay changes. In that case, I would use a variable to
hold the change amount, e.g., dAccuracyDisplay (i.e., "delta"
AccuracyDisplay), so that the calculation becomes merely
AccuracyDisplay = AccuracyDisplay + dAccuracyDisplay
Yes, you might still need a mess of code to compute dAccuracyDisplay,
but I like to separate the mess that computes dAccuracyDisplay from
the operation that actually uses it, I find such separation aids my
comprehension.
Next, once I have graduated to using a variable (instead of literal
values) in the computation, I would consider using a
multi-dimensional array to hold a table of the possible point values,
and use numeric codes that will act as indices into the table for
each condition. E.g., I might use 0 instead of "OldNew" for that
TestType, 0 instead of "Old" for that StatusOldNew, etc. This
admitedly adds a bit of indirection, but indirection that will could
greatly simplify our computation. I would of course still need some
code to set up the table at the start of the session, but with that
done my computaton during the run might reduce to a single line, e.g.,
AccuracyDisplay = AccuracyDisplay + PointTable( _
CInt(c.getattrib ("TestType")), _
CInt(MasterList.getattrib("StatusOldNew")), TestSlide.ACC )
But I have probably missed something really obvious, so I hope
someone else here will chime in and set me straight.
One more style point, then a homework assignment. Of course, it is
good practice to end every Select Case with a Case Else to catch
unforeseen cases, e.g.,
Case Else
MsgBox "Invalid option."
I trust you left this out of your example simply because it was not
germane to your question.
And now your homework: Work through Chapter 4, "Using E-Basic", of
the User's Guide that came with E-Prime, and study any edition of
"VBA for Dummies" (still available at Amazon.com, get a used copy).
Regards,
-- David McFarlane, Professional Faultfinder
"For a successful technology, reality must take precedence over
public relations, for nature cannot be fooled." (Richard Feynman,
Nobel prize-winning physicist)
At 1/9/2011 09:00 PM Sunday, you wrote:
> I have learned so much about E-Prime through this group and
> through butting my head against E-Prime's metaphorical wall (i.e.
> scripting). It is now time for me to post a question.
>
> My experiment:
>
> This memory experiment asks participants to study a list of
> pictures. At test, they are presented with both the pictures they
> just studied and new pictures. Their job is to discriminate
> between studied and non-studied pictures (e.g. "Was this old or
> new?"). In this experiment, there are 5 such study-test
> blocks. My manipulation is to use five different payoff matrices
> which correspond to the five study-test blocks. Each study-test
> block (and thus, each payoff matrix) will be presented in random
> order to each new participant.
>
> My question:
>
> I am trying to create a feedback counter to present to
> participants after each trial. I can do it, but my script requires
> many nested "If...Then" statements and "Select Case"
> statements. The reason for this is because of the following:
>
> 1) I have two experiment startup conditions. I have an "Old New"
> Condition and a "PDP" condition (not important what these actually
> mean). As a result, I also have two different SlideObjects
> (TestSlideOLDNEW and TestSlide) that correspond to each
> condition. The TestSlide objects collect trial responses.
>
>2) I have 5 different "Payoff Matrix" conditions (I call them A, B,
>C, D, and E).
>
>3) I need to assign different 'points' to each correct and incorrect response.
>
>4) For each correct and incorrect response, I need to assign
>different point values based on the type of picture presented (e.g.
>old/studied or new/non-studied). This corresponds to Hits, Misses,
>False Alarms, and Correct Rejections.
>
> I will try to explain what I have in the following script:
>
>
>**********************************************************************************************************************
>
>***********************************************************************************************************************
>
>'This If...Then statement refers to (1) above
>
>If c.getattrib ("TestType") = "OldNew" then
>
>Select Case MasterList.getattrib ("Payoff") ' This refers to the
>five different Payoff Matrices
>
> Case "A" 'First payoff matrix
>
> If MasterList.getattrib ("StatusOldNew") = "Old" then
>
> If TestSlideOLDNEW.ACC = 1 then 'Hit Rate
>
> AccuracyDisplay =
> AccuracyDisplay+1 'counter
>
> c.setattrib
> "Accuracy", AccuracyDisplay 'Sets Accuracy attribute so that I can
> display up-to-date point system per trial
>
> Elseif TestSlideOLDNEW.ACC = 0 then 'Miss
>
> Accuracy Display =
> AccuracyDisplay-1
>
> c.setattrib
> "Accuracy", AccuracyDisplay
>
> Else MsgBox "Conservative A
> condition payoff matrix error Status Old"
>
> End if
>
> Elseif MasterList.getattrib("StatusOldNew")
> = "New" then
>
> If TestSlideOLDNEW.ACC = 1 then
> 'Correct Rejection
>
> AccuracyDisplay =
> AccuracyDisplay+5
>
> c.setattrib
> "Accuracy", AccuracyDisplay
>
> Elseif TestSlideOLDNEW.ACC = 0
> then ' False Alarm
>
> AccuracyDisplay =
> AccuracyDisplay-5
>
> c.setattrib
> "Accuracy", AccuracyDisplay
>
> Else MsgBox "Conservative A
> condition payoff matrix error Status New"
>
> End if
>
> Else MsgBox "StatusOLDNEW payoff matrix error"
>
> Case "B"
>
>.
>
>.
>
>.
>
>Case "E"
>
>
>
>Elseif c.getattrib("TestType") = "PDP" then
>
> Select Case.........
>
>.
>
>.
>
>.
>
>***********************************************************************************************************************
>
>***********************************************************************************************************************
>
>You can see that much of my script seems redundant, but I cannot
>figure out how to condense the script any further. I am familiar
>with For...Next loops, SubRoutines, Arrays, If...Then, IIf, and
>Select...Case functions as I've read the E-Basic help on these
>functions and used them in the past. However, my personal
>experience with Subroutines and Arrays is limited, but I understand
>them enough to have been able to use them in the past
>effectively. The solutions I've thought of merely require
>rearranging everything in IIF, If...Then, or Select...case
>functions, but this seems like a rather unnecessary
>rearrangement. I've also thought of declaring an array so that I
>can just add values to the counter within a For...Next loop, but
>this also seems unnecessary because I could just as easily input the
>actual integer values.
>
>Therefore, my question is, how can I condense this script
>further? I will continue to try to innovate, but I would also like
>to hear any comments/suggestions that any of you might have. I plan
>to post my (hopefully, elegant) solution once I reach it.
>
>If anything seems unclear, please let me know.
>
>Thank you!
>
>Caleb J. Picker
--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-prime at googlegroups.com.
To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.
More information about the Eprime
mailing list