Post Reply 
Trapping Error in Do2VStats()
03-10-2018, 05:47 PM
Post: #1
Trapping Error in Do2VStats()
I am writing a program to select the best fit from the available models in the Statistics 2Var app. I plan to submit it when everything is working.

(It publishes two functions that compute the available criteria for model selection. R square should be used to evaluate the performance of the selected model. It should [b]not[/b] be used to select the model. AICc and adjusted R square are available as the model selection criterion.)

I am able to step through the program for the first several models and see the correct values in the variables but when the error occurs, the debugger kicks me out with a syntax error message. I tried to trap it with IFERR but I am not getting anywhere.

(I have been further hampered by the instability of the virtual calculators on macOS and iOS where the button and field labels disappear or changes in the program editor are not saved. This behavior is particularly troublesome in the debugger. I have to close the VC every five minutes or so.)

Thanks in advance for any help you might offer!

Code:
#pragma mode( separator(.,;) integer(h32) )

EXPORT AICc(sse,n,p)
BEGIN
 IF sse <= 0 THEN MSGBOX("SSE must be greater than zero"); RETURN "Error"; END;
 IF n < 3 THEN MSGBOX("n must be greater than 2"); RETURN "Error"; END;
 IF n-p < 2 THEN MSGBOX("n must be greater than p by 2"); RETURN "Error"; END;
 IF p < 1 THEN MSGBOX("p must be greater than zero"); RETURN "Error"; END;
 RETURN n * LN( 2 * Pi() * sse / n ) + (n + p) / (1 - (p + 2) / n);
END;

EXPORT AdjRSqr(rSqr,n,p)
BEGIN
 IF rSqr <= 0 OR rSqr >= 1 THEN MSGBOX("R square must be in interval (0,1)"); RETURN "Error"; END;
 IF n < 3 THEN MSGBOX("n must be greater than 2"); RETURN "Error"; END;
 IF n-p < 1 THEN MSGBOX("n must be greater than p"); RETURN "Error"; END;
 IF p < 1 THEN MSGBOX("p must be positive"); RETURN "Error"; END;
 RETURN 1-((n-1)*(1-rSqr)/(n-p));
END;

criterion := 1;
bestfitresults := MAKELIST("",X,1,11);

VIEW "Start", START()
BEGIN
  criterion := 1;
  bestfitresults := MAKELIST("",X,1,11);
  STARTVIEW(2,1);
END;

VIEW "Select Criterion",SELECTCRIT()
BEGIN
  CHOOSE(criterion,"Criterion","AICc","Adj R Sqr");
  STARTVIEW(2,1);
END;

VIEW "Best Fit",BESTFIT()
BEGIN
  LOCAL p,f,res,sse;
  p := {2,2,2,2,2,2,3,3,4,5,4};
  FOR f FROM 1 TO 11 DO
    S1(4) := f;
    Do2VStats(S1);
    IF criterion == 1 THEN
      res := Resid(S1);
      sse := ╬úLIST(res.*res);
      bestfitresults(f) := AICc(sse,NbItem,p(f));
    ELSE
      bestfitresults(f) := AdjRSqr(CoefDet,NbItem,p(f));
    END;
  END;
  // identify best fit (minimum AICc or maximum adj R square) and set S1
  RETURN bestfitresults;
  STARTVIEW(1,1);
END;

VIEW "Plot Criterion",PLOTCRITERION()
BEGIN
  // push bestfitresults to D1 and make line plot with autoscale in Statistics 1Var
END;

VIEW "Autoscale",AUTOSCALE()
BEGIN
  STARTVIEW(10,1);
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Trapping Error in Do2VStats() - mark4flies - 03-10-2018 05:47 PM



User(s) browsing this thread: 1 Guest(s)