How to save a prediction formula column with a specific name via JSL?Dear all,
I am running some generalised linear model via a JSL script.
How can I save the prediction formula to a column with a specific name?
All I managed to find (Automate saving of prediction formula using JMP script?) was something like:
GLM = Fit Model (......);
GLM << prediction formula;
However:
1) can I choose the name of the column which will store the prediction formula? JMP will automatically save it to: "Pred Formula 'Target Variable'"
2) Is this functionality documented anywhere? I found it on the forum above, but not in JMP's documentation
3) Does the same syntax work for other platforms (e.g. partition)?
Thanks.
Re: JSL scripting: how to save prediction formulae?Ian's reply answers concerns #1 and #3, while user ms answers question #2 about documentation surrounding the JMP Scripting Language (JSL).
@ian_jmp:
Generally 'Save Prediction Formula' is consistent across platforms. The name(s) of the saved columns are indeed fixed, but you can rename them using things like:
dt <SPAN class="token operator">=</SPAN> <SPAN class="token function">Open</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token string">"$SAMPLE_DATA/Big Class.jmp"</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
cols <SPAN class="token operator">=</SPAN> dt <SPAN class="token operator"><</SPAN><SPAN class="token operator"><</SPAN> GetColumnNames<SPAN class="token punctuation">(</SPAN><SPAN class="token string">"String"</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
<SPAN class="token function">For</SPAN><SPAN class="token punctuation">(</SPAN>c<SPAN class="token operator">=</SPAN><SPAN class="token number">1</SPAN><SPAN class="token punctuation">,</SPAN> c<SPAN class="token operator"><=</SPAN><SPAN class="token function">NItems</SPAN><SPAN class="token punctuation">(</SPAN>cols<SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">,</SPAN> c<SPAN class="token operator">++</SPAN><SPAN class="token punctuation">,</SPAN>
<SPAN class="token function">Column</SPAN><SPAN class="token punctuation">(</SPAN>dt<SPAN class="token punctuation">,</SPAN> cols<SPAN class="token punctuation">[</SPAN>c<SPAN class="token punctuation">]</SPAN><SPAN class="token punctuation">)</SPAN> <SPAN class="token operator"><</SPAN><SPAN class="token operator"><</SPAN> SetName<SPAN class="token punctuation">(</SPAN><SPAN class="token string">"New "</SPAN><SPAN class="token operator">||</SPAN>cols<SPAN class="token punctuation">[</SPAN>c<SPAN class="token punctuation">]</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
<SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
On rare occasions it can be helpful to use 'Get Column Names' before and after the columns are created, comparing the two lists to infer the names of the new columns.
@ms:
Regarding documentation for JSL, I think that the Scripting Index (Help menu) is a great resource, packed with ready-to-use examples. And yes, << Prediction Formula is there.
Re: How to save a prediction formula column with a specific name via JSL?Continuing your example:
GLM = Fit Model (......);
pf = GLM << prediction formula;
pf << Set Name( "my name" );
Yes, this approach should work with any of the modeling platforms.
Re: JSL scripting: how to save prediction formulae?<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />I removed the double quotes from :My Saved prediction and now it all works fine.
Thank you for pointing me to the Scripting Index - very useful!
Re: JSL scripting: how to save prediction formulae?The empty box may indicate that the column :My saved Prediction (should not be within double quotes) does not exist in the current data table. Check spelling.
Regarding documentation for JSL, I think that the Scripting Index (Help menu) is a great resource, packed with ready-to-use examples. And yes, << Prediction Formula is there.
Re: JSL scripting: how to save prediction formulae?Mmm, it sounds very convoluted. What I have found is that if my target variable is called "My Target", the column will be called "Pred Formula My Target", so I use:
GLM = Fit Model (......);
GLM << prediction formula;
Column("Pred Formula My Target") << Set Name("New Column Name");
How about documentation? Is this properly documented anywhere in the JSL documentation? I haven't managed to find it. I am new to JMP scripting, but first impressions are that it is a powerful language with a convoluted syntax and poor documentation, a bit like R in a way - but I would expect better documentation from a commercial software!
Finally, I create another column which multiplies the prediction by something else:
New Column("My new calculation", Numeric, Formula( :"My saved Prediction" * :another_field ));
where "My saved prediction" has spaces in the name, another_field does not. The formula is calculated correctly, but if I right click on the heading and go to formula, I see an empty box multiplied by another_field. Is this a bug in JMP? Should I have specified the formula differently?
Thank you.
Re: JSL scripting: how to save prediction formulae?Generally 'Save Prediction Formula' is consistent across platforms. The name(s) of the saved columns are indeed fixed, but you can rename them using things like:
dt = Open("$SAMPLE_DATA/Big Class.jmp");
cols = dt << GetColumnNames("String");
For(c=1, c<=NItems(cols), c++,
Column(dt, cols[c]) << SetName("New "||cols[c]);
);
On rare occasions it can be helpful to use 'Get Column Names' before and after the columns are created, comparing the two lists to infer the names of the new columns.