Customizing Inference App? - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Customizing Inference App? (/thread-2435.html) Customizing Inference App? - mbeddo - 11-16-2014 12:26 AM In my physics lab the other night, we were validating the equation for the magnetic force on a current carrying wire: Force = Current*Length*MagneticField. The HP Prime was very useful and the students like it over their TI-84 and nSpire calculators - the touchscreen was a hit, as well as a more rational layout of keys. We used the Spreadsheet app to collect our raw data and process it. Then we copied the appropriate columns into the Statistics_2Var app so we could calculate statistics for the Force vs Current and Force vs Length graphs. The magnetic field was fixed but we didn't know it's strength. So I set up a regression between Current*Length and Force, knowing the slope would be the magnetic field strength. We got -0.11 Tesla. I wanted to do inference on the slope (magnetic field), so I started the Inference app, went to the Symbolic view to select the "Regression" method and the "Interval: Slope" type. In the Numeric view the Xlist and Ylist were empty. There didn't seem to be a way for importing from a list from another app. I could do this in the Home view, of course, but I want to get my feet wet learning to program the HP Prime, so I looked for a way to customize the context-sensitive menus at the bottom of the Numeric view. I couldn't find a way to do it in the User Guide. So I copied the Inference app to "Inference Copy" and then added a VIEW: EXPORT Inference_Copy() BEGIN END; VIEW "Copy C1, C2 into Xlist, Ylist", COPY_C1C2() BEGIN Xlist := Statistics_2Var.C1; Ylist := Statistics_2Var.C2; END; Now I can click on the View button and copy the data in one step. Of course, this could be made more sophisticated (once I learn how) asking me from which app to copy data from, etc. But I'd really like this operation to be available as a context menu in the Numeric view (where I think it belongs) if the inference method is regression (the other methods have a context menu "Import" which brings in statistics from the other apps). Is this biting off more than I should chew? Perhaps a better solution is to provide a function for NumSetup? RE: Customizing Inference App? - Han - 11-16-2014 01:17 AM You could create a replacement function for the [Num] key by redefining the Num() function. At the start of the Num() function, ask the user if they want to import data (you could use INPUT() to do this) and from where, import it if needed, and then use STARTVIEW() to load up the actual built-in Num view as the last command of the Num() function. It doesn't quite have the same effect as having a dedicated menu key, though. RE: Customizing Inference App? - mbeddo - 11-16-2014 02:08 AM Han, Great idea! The code I used is this: EXPORT Inference_Copy() BEGIN END; Num() BEGIN IF MSGBOX("Import C1/C2?", 1) THEN Xlist := Statistics_2Var.C1; Ylist := Statistics_2Var.C2; END; STARTVIEW(2, 1); END; Seems to give me what I wanted. It wasn't clear to me that STARTVIEW(2, 1) wouldn't call this Num(), resulting in an infinite loop, or the Num() of the built-in app. Glad to see it calls the Num() of the built-in app. Now I'll work on the INPUT block. Thanks for the advice! RE: Customizing Inference App? - Han - 11-16-2014 02:38 AM (11-16-2014 02:08 AM)mbeddo Wrote:  Seems to give me what I wanted. It wasn't clear to me that STARTVIEW(2, 1) wouldn't call this Num(), resulting in an infinite loop, or the Num() of the built-in app. Glad to see it calls the Num() of the built-in app. Now I'll work on the INPUT block. Thanks for the advice! Yeah, STARTVIEW() uses the built-in function. The thought is that if you wanted the customized function you would simply call Num() and not STARTVIEW(). As for creating a program for input, you probably have to do string manipulation and use EXPR(). For example: AppName:="Statistics_2Var.C"; ColNum:=1; Destination:="Xlist"; // the values above you could use an INPUT() command to obtain EXPR(Destination + ":=" + AppName + ColNum); EDIT: changed to fit your particular app a bit better. You can modify this to a generic import function that can import to/from any app. Make sure to qualify the destination name, too, to avoid any conflicts in various apps. For example, it's safer to do "Statistics_2Var.C1:=Spreadsheet.A1:A10" than to simply do "C1:=Spreadsheet.A1:A10" as the latter may store the result in cell C1 of the spreadsheet app if you're running from the Spreadsheet app and not the Stat2Var app RE: Customizing Inference App? - Tim Wessman - 11-16-2014 04:03 AM Sorry about not having the data import directly! It really was purely an oversight that I realized at the last minute and was unable to correct due to the lateness in the release schedule. Glad to see you found a solution that works for you. That reaction you report with the students is pretty much consistent with what we see and hear about everywhere. :-) RE: Customizing Inference App? - mbeddo - 11-18-2014 08:24 AM Folks have been very helpful - great forum! I provided an NumSetup() function for my Inference_Copy() program. When in Inference_Copy app, I can go into the NumSetup view and choose which app to import data from (Statistics_1Var, Statistics_2Var, or Spreadsheet), and depending on the choice ask for the two columns from which to import data into Xlist and Ylist. The program is below. It would be nice to use Inference_Copy.Method, because I only want to run the code below when the "Regression" method is selected in the symbolic view (the other methods already have import functionality), but it seems the global variable Inference_Copy.Method only has two values: 0 or 1, and there are 4 possible choices! One other problem is when copying from a spreadsheet column. It seems if the column I want to copy is a computed column (i.e. values come from a spreadsheet formula) then the copy fails with a "Error: Unmatch control word" unless I specify a row range. I wonder what's going on here? - Mike EXPORT Inference_Copy() BEGIN END; NumSetup() BEGIN LOCAL rtn, src, x, y; rtn := CHOOSE(src, "Which app to import data from?", {"Statistics 1Var", "Statistics 2Var", "Spreadsheet"}); if (rtn == 0) THEN RETURN end; // we expect strings, so let the program know this. x := ""; y := ""; CASE // import from Statistics 1Var IF (src == 1) THEN INPUT({x,y}, "Configure Xlist and Ylist", {"Xlist", "Ylist"}, {"Specify the source Dn column for Xlist", "Specify the source Dn column for Ylist"}); EXPR("Xlist := Statistics_1Var." + x); EXPR("Ylist := Statistics_1Var." + y); END // import from Statistics 2Var IF (src == 2) THEN INPUT({x,y}, "Configure Xlist and Ylist", {"Xlist", "Ylist"}, {"Specify the source Cn column for Xlist", "Specify the source Cn column for Ylist"}); EXPR("Xlist := Statistics_2Var." + x); EXPR("Ylist := Statistics_2Var." + y); END // import from Spreadsheet IF (src == 3) THEN INPUT({x,y}, "Configure Xlist and Ylist", {"Xlist", "Ylist"}, {"Specify the source column and row range for Xlist", "Specify the source column and row range for Ylist"}); EXPR("Xlist := Spreadsheet." + x); EXPR("Ylist := Spreadsheet." + y); END END; END; RE: Customizing Inference App? - Han - 11-18-2014 02:03 PM It seems you can set the Method to values from 0 to 3 and the Symb view will change accordingly. However, the built-in app itself doesn't seem to set the Method value to anything other than 0 or 1. WARNING: Don't set it higher than 3; I think there may be a bug (on my emulator, it will lead to a crash). As for the spreadsheet, the reason is because the columns aren't lists. The columns of the statistics apps are lists, and the columns of the inference app is a list. Using Spreadsheet.B returns the global variable B, which is always a real number. Therefore storing a real number into a list such as Xlist will result in an error. Edit: Also, columns and cells in a spreadsheet are typically considered "non-terminating" in the sense that there is no "end" to a row or column other than our own interpretation of where the end is supposed to be. RE: Customizing Inference App? - Han - 11-18-2014 02:23 PM Here's a slightly smaller piece of code: Edit: fixed minor typos Code: ``` NumSetup() BEGIN LOCAL rtn, src, x, y; LOCAL insert:={"Dn", "Cn", "and row range"}; LOCAL app:={"Statistics_1Var", "Statistics_2Var", "Spreadsheet"}; rtn := CHOOSE(src, "Which app to import data from?", app); if (rtn == 0) THEN RETURN end; // we expect strings, so let the program know this. x := ""; y := "";  if INPUT({x,y}, "Configure Xlist and Ylist",   {"Xlist", "Ylist"},     {     "Specify the source column " +insert(src)+" for Xlist",      "Specify the source column " +insert(src)+" for Ylist"   } ) then   EXPR("Xlist :=" + app(src) + "." + x);   EXPR("Ylist :=" + app(src) + "." + y); end; END;``` RE: Customizing Inference App? - Tim Wessman - 11-18-2014 02:37 PM (11-18-2014 02:03 PM)Han Wrote:  WARNING: Don't set it higher than 3; I think there may be a bug (on my emulator, it will lead to a crash). I just get an invalid input. The input is definitely limited from 0-3. When did you see this behavior? Running the program? Manually? RE: Customizing Inference App? - Han - 11-18-2014 03:50 PM (11-18-2014 02:37 PM)Tim Wessman Wrote:   (11-18-2014 02:03 PM)Han Wrote:  WARNING: Don't set it higher than 3; I think there may be a bug (on my emulator, it will lead to a crash). I just get an invalid input. The input is definitely limited from 0-3. When did you see this behavior? Running the program? Manually? Odd, the emulator on my office machine exits gracefully. But the one from home crashed -- and only for input values outside of 0-3. I'll have to check it again later this evening when I get home. Edit: yeah, it is reproducible at home which makes me suspect I have corrupted memory. RE: Customizing Inference App? - salvomic - 03-14-2015 09:24 PM (11-16-2014 12:26 AM)mbeddo Wrote:  ... I wanted to do inference on the slope (magnetic field), so I started the Inference app, went to the Symbolic view to select the "Regression" ... So I copied the Inference app to "Inference Copy" and then added a VIEW: ... hi, please, do you think this method could be useful also to import data into Chi square test? Perhaps better with Two way test than with Goodnes of fit... If yes, what to add in Inference Copy? thank you, Salvo RE: Customizing Inference App? - salvomic - 05-14-2015 09:48 AM (11-16-2014 12:26 AM)mbeddo Wrote:  In my physics lab the other night, ... So I copied the Inference app to "Inference Copy" and then added a VIEW: ... mbeddo, Tim, please: is it still necessary to save Inference Copy in the Apps or the new Inference App in 7820 already includes the stuff we discussed in this thread? Thank you Salvo