Can't get AddObservation to work, or plague of the Type Mismatch

David McFarlane mcfarla9 at msu.edu
Fri Mar 11 17:44:51 UTC 2011


Micah,

I didn't see this thread until today, I know I'm 
late and you have already gone off in a different 
direction.  And I very rarely look at other 
people's code, but I rather like the Summation 
object and I wanted to see how you managed to get 
a "Type mismatch" error, and I wanted to address 
this for others who may chance across this 
thread.  (You also did a nice job of posting your 
program for download, and you kept the problem 
program to a small scale).  So here goes.

So, the error takes place at the line

stopaccuracy.AddObservation c.GetAttrib("ogperf")

As others may have noted, when the program 
reaches this line, the "ogperf" attribute is 
empty.  And you cannot add an empty observation 
to a Summation object, you must have a numeric 
value (BTW, no real need to cast it to a numeric 
type, E-Basic will take care of that for you 
automatically, but go ahead and use CInt() if it makes you feel better :) ).

Reading the code further, you give a value to 
"ogperf" only when "trialtype" = "lure".  As it 
turns out, your first trial in List3 has a 
trialtype of "gotrial", thus "ogperf" does not 
get a value and you get the the Type mismatch error.

Just to test this out, I used a "lure" trial for 
the first trial, and sure enough that worked 
without any error.  (So you see, the problem 
would not be apparent from reading the code 
alone, it has to be seen in the context of the List that runs it.)

So as I understand it, you only really want to 
gather observations for "lure" type trials.  In 
that case, you should put your .AddObservation 
into the If(trialtype) clause, so that your code looks more like

If (c.GetAttrib("trialtype") = "lure") then
     if (TextDisplay1.RT = 0) then
         c.SetAttrib "ogperf", 1
     else
         c.SetAttrib "ogperf", 0
     end if
     stopaccuracy.AddObservation c.GetAttrib("ogperf")
end if
if ( (c.GetAttrib("awaretrial") = "1") and (killme = 1) ) then
     if (TextDisplay1.RESP = "2") then
         c.SetAttrib "ogaware", 0
     else
         c.SetAttrib "ogaware", 1
     end if
end if
if (c.GetAttrib("ogperf") = "0") then
     killme = 1
else
     killme = 0
end if

etc.

I tried this out and it worked without error, 
though I did not go as far as seeing whether it 
produces the computations that you desire.  You 
might also do more to generally clean up the 
logic.  I leave all that as an exercise for you.

-- David McFarlane, Professional Faultfinder


At 3/10/2011 12:51 PM Thursday, Michiel Spape wrote:
>Hi,
>No problem! This one should be easy (I get it 
>all the time with languages less forgiving than 
>basic): I bet numtrials equals to 0, therefore
>cint(cstr(trialscorrect / numtrials / 0.01))
>… which wasn’t correct anyway (should have tested), it is
>cstr(cint(trialscorrect / numtrials / 0.01))
>… but that’s not the problem (presumably) – also 
>the cstr is unnecessary, so let’s make it
>cint(trialscorrect / numtrials / 0.01)
>
>but finally, this, I’m pretty sure, results 
>somewhere along the line in trialscorrect / 0. 
>Divided by zero, or infinity, which doesn’t fit 
>in a mere integer, it will tell you overflow. 
>Notice however that somewhere along the line, 
>numtrials and trialnum are used interchangeably, 
>a very common mistake if you’re me:
>
>c.SetAttrib "thismuch", cint(trialscorrect / TrialNum / 0.01)
>
>sorted!
>Best,
>Mich
>
>
>Michiel Spapé
>Research Fellow
>Perception & Action group
>University of Nottingham
>School of Psychology
>www.cognitology.eu
>
>From: e-prime at googlegroups.com 
>[mailto:e-prime at googlegroups.com] On Behalf Of Micah Allen
>Sent: 10 March 2011 17:08
>To: e-prime at googlegroups.com
>Subject: RE: Can't get AddObservation to work, or plague of the Type Mismatch
>
>
>woops, so close-
>
>The last bit where I dump the variables into an 
>attribute is giving an overflow error. Any ideas?
>On Mar 9, 2011 5:39 PM, "Michiel Spape" 
><<mailto:Michiel.Spape at nottingham.ac.uk>Michiel.Spape at nottingham.ac.uk> wrote:
> > Hiya,
> > Well, let's see how far you'll get :) I 
> thought I might add that I generally have two 
> global variables (i.e. declared in the User 
> tab), one being TrialNum, which just adds one 
> up to the trial, and one TrialsCorrect.
> > So, every trial, I tend to have an inline with the following:
> > TrialNum = TrialNum + 1 'just so that number 
> of trials is counted, also useful if you want to present a break
> > TrialsCorrect = TrialsCorrect + 
> myStimulus.ACC 'which saves one IF/THEN object.
> >
> > Visual basic tends to be a bit tricky in 
> terms of variables being converted on the spot, 
> whether you like it or not, but if you just 
> want to know the percentage, the following tends to work pretty well:
> > TrialNum = 30 'just as an example, 30 trials done so far
> > TrialsCorrect = 10 'just as an example, 10 trials correct
> > Debug.print cint(cstr(trialscorrect / numtrials / 0.01)) "% correct"
> > This returns "33% correct" (in the output).
> >
> > So, if you would just dump that into a new 
> attribute (don't add it to the list, it confuses things sometimes):
> > c.SetAttrib "thismuch", cint(cstr(trialscorrect / numtrials / 0.01))
> >
> > and have a slide, saying "You had [thismuch]% 
> correct", you're basically there (just tested 
> it). Not to say you can't do the same with 
> summation objects, but the above, taking out my 
> debug, takes only 3 lines of code (excluding 2 
> lines of user script variable declarations).
> > Cheers,
> > Mich
> >
> >
> >
> > Michiel Spapé
> > Research Fellow
> > Perception & Action group
> > University of Nottingham
> > School of Psychology
> > <http://www.cognitology.eu>www.cognitology.eu
> >
> >
> > -----Original Message-----
> > From: 
> <mailto:e-prime at googlegroups.com>e-prime at googlegroups.com 
> [mailto:e-prime at googlegroups.com] On Behalf Of Micah
> > Sent: 09 March 2011 16:06
> > To: E-Prime
> > Subject: Re: Can't get AddObservation to 
> work, or plague of the Type Mismatch
> >
> > Hi Michiel,
> >
> > Thanks for the useful reply! Ogperf and ogaware are actually list
> > objects, and the related code is designed to log stops and successful
> > error reports. So the first bit of code should be resolving to either
> > a '1' or a '0' for either accurate/inaccurate stop or correct error
> > report/missed error report. That being said I see your point with the
> > need to simplify and had wondered if I could get by without the
> > summation object. My worry is that, sense the accuracy data is not
> > generated directly by the list or procedure, I need this summation
> > object to collect data from the ogperf ogaware inline. The last bit
> > ( c.SetAttrib "errorawareness",
> > Format((errorawareness.Mean),"Percent")) is supposed to then format
> > the summation object for placement in the end of block report
> > ("Congratulations, you successfully inhibited on [stopaccuracy] of
> > trials and reported your errors [erroraware] of the time").
> >
> > Will try to wrap my head around how to do this without the summation-
> > appreciate your help!
> >
> >
> >
> > On Mar 9, 4:55 pm, Michiel Spape 
> <<mailto:Michiel.Sp... at nottingham.ac.uk>Michiel.Sp... at nottingham.ac.uk>
> > wrote:
> >> Hiya,
> >> Ugh, lots of code. Forgive me, like many 
> coding people, I tend to be lazy and simply 
> won't read long threads. I've never had any use 
> for this "summation object" deal, but your code is really quite confusing:
> >>
> >> > > dim stopaccuracy as Summation
> >> > > dim erroraware as Summation
> >> > > c.SetAttrib "stopaccuracy", Format((stopaccuracy.Mean),"Percent")
> >> > > c.SetAttrib "errorawareness", Format((errorawareness.Mean),"Percent")
> >> > > stopaccuracy.AddObservation c.GetAttrib("ogperf")
> >> > > errorawareness.AddObservation c.GetAttrib("ogaware")
> >>
> >> What exactly are you doing here? 
> Stopaccuracy is both a "summation" and an 
> "attribute in a list". Errorwareness is only 
> semi-overlapping with this attribute, although 
> I see no reason why you would want this. Ogperf 
> is not even an attribute but a local variable. 
> If you have declared it somewhere, it probably 
> looks into a list anyway, finds a question 
> mark, tries to put this into stopaccuracy. 
> Thus, what you get is 
> StopAccuracy.AddObservation ?, or, dbl(?), which doesn't work either.
> >>
> >> If you want to find out what's going on with 
> the mismatch (one of the more simpler things to 
> solve):>stopaccuracy.AddObservation c.GetAttrib("ogperf")
> >>
> >> Then try change this into:
> >> stopaccuracy.AddObservation 0
> >> if the latter works but the former doesn't, 
> then c.GetAttrib("ogperf") probably receives a 
> string instead, or, in other words, Ben would 
> be right. See what ogperf is by doing 
> "debug.print c.GetAttrib("ogperf"). So, try 
> beginning simple with working code, then add - rather than the opposite.
> >>
> >> So, start with as clean and working code as 
> possible. My suggestion would be to start with 
> getting rid of the summation stuff (after all, 
> what more is stopaccuracy.mean then merely 
> numberofstopaccuratetrials / numberoftrials?) 
> and the c.getattrib/set stuff until you can get 
> everything working on one level.
> >> Cheers,
> >> Mich
> >>
> >> Michiel Spapé
> >> Research Fellow
> >> Perception & Action group
> >> University of Nottingham
> >> School of 
> <http://Psychologywww.cognitology.eu>Psychologywww.cognitology.eu
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> -----Original 
> <mailto:Message-----From%3Ae-prime at googlegroups.com>Message-----From:e-prime at googlegroups.com[mailto:e-prime at googlegroups.com]On 
> Behalf Of Micah
> >> Sent: 09 March 2011 15:19
> >> To: E-Prime
> >> Subject: Re: Can't get AddObservation to 
> work, or plague of the Type Mismatch
> >>
> >> Hi Ben,
> >>
> >> Sincere thanks for your suggestion. Helped me to feel like I'm getting
> >> somewhere in my understanding of E-basic, as I had the same idea.
> >> Sadly neither CInt or CDbl used in that way change the error. I also
> >> tried declaring erroraware and stopaccuracy as doubles, and tried
> >> converting them into new variables that would be numbers. I'm not sure
> >> I did that correctly however.
> >>
> >> Thanks for your help- i'll be really excited if we can solve this.
> >>
> >> On Mar 9, 3:17 pm, ben robinson 
> <<mailto:baltimore.... at gmail.com>baltimore.... at gmail.com> wrote:
> >> > try changing them to:
> >> > stopaccuracy.AddObservation CInt(c.GetAttrib("ogperf"))
> >> > errorawareness.AddObservation CInt(c.GetAttrib("ogaware"))
> >>
> >> > or CDbl(...) if CInt(...) isn't what you need.
> >> > i think the problem might be that when you 
> c.GetAttrib the value it pulls
> >> > from the list is understood as a string, 
> rather than some sort of number...
> >>
> >> > On Wed, Mar 9, 2011 at 8:34 AM, Micah 
> <<mailto:ucfmi... at gmail.com>ucfmi... at gmail.com> wrote:
> >> > > Hello,
> >>
> >> > > This is probably a very easy to solve problem, but it's just about
> >> > > beaten me down. I am trying to make a training script for my error-
> >> > > awareness paradigm that can log inhibition and error-awareness
> >> > > performance and then report these to the subject at the end of the
> >> > > trial. The task is very simple and works fine, as does the performance
> >> > > logging. I can't seem to get my summation object to work though-
> >> > > everytime it gives me a 'type mismatch'. I've tried creating a
> >> > > variable from the logging vars in a double format but that does not
> >> > > fix it. Can someone take a look at my code and see what's up?
> >>
> >> > > I start with the following setup inline and usertab code:
> >> > > 'setup inline
> >> > > set stopaccuracy = New Summation
> >> > > set erroraware = New Summation
> >>
> >> > > 'usertab
> >> > > dim killme as integer
> >> > > dim stopaccuracy as Summation
> >> > > dim erroraware as Summation
> >> > > dim ogperf as double
> >> > > dim ogaware as double
> >>
> >> > > My inline that logs awareness and performance, and (is supposed to)
> >> > > fill the summation object with these information for reporting to the
> >> > > subject, looks like this:
> >>
> >> > > If c.GetAttrib("trialtype") = "lure" then
> >> > >        if TextDisplay1.RT = 0 then
> >> > >                c.SetAttrib "ogperf", 1
> >> > >        else
> >> > >                c.SetAttrib "ogperf", 0
> >> > >        end if
> >> > > end if
> >>
> >> > > if c.GetAttrib("awaretrial") = "1" and killme = 1 then
> >> > >        if TextDisplay1.RESP = "2" then
> >> > >                c.SetAttrib "ogaware", 0
> >> > >        else
> >> > >                c.SetAttrib "ogaware", 1
> >> > >        end if
> >> > > end if
> >>
> >> > > if c.GetAttrib("ogperf") = "0" then
> >> > >        killme = 1
> >> > > else
> >> > >        killme = 0
> >> > > end if
> >>
> >> > > stopaccuracy.AddObservation c.GetAttrib("ogperf")
> >> > > errorawareness.AddObservation c.GetAttrib("ogaware")
> >>
> >> > > Debug.Print stopaccuracy.Mean
> >> > > Debug.Print erroraware.Mean
> >>
> >> > > c.SetAttrib "stopaccuracy", Format((stopaccuracy.Mean),"Percent")
> >> > > c.SetAttrib "errorawareness", Format((errorawareness.Mean),"Percent")
> >>
> >> > > It's these lines that give me the type mismatch:
> >> > > stopaccuracy.AddObservation c.GetAttrib("ogperf")
> >> > > errorawareness.AddObservation c.GetAttrib("ogaware")
> >>
> >> > > Link to script:<http://bit.ly/hKCcmo>http://bit.ly/hKCcmo
> >>
> >> > > Best,
> >> > > Micah

-- 
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