cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Lavik17
Level II

Calculating rolling slopes

Hi all,

I have this data table (attached) that I am trying to analyze with a jsl script. I havn't gone very far... I am aware of the `Col Moving Average` function but couldn't get it to fit my needs. I'd appericaite your input!

 

The script should

1. Sort the the the "Minutes" column by "Group" column

2. Calculate the rolling slopes for the "Reading" by "Group".

 

The output should be two added columns:

1. The rolling slope, but only for rows that have enough rows before them to calculate the rolling slope. For example, if the window size is set to 5, then rolling slope should only start at row 5. 

2. The distance between the two edge time points of the rolling window divided by 2. For example, if the first and last time points of the current window are 3 and 8, this value should be 2.5.

 

Thank you!!

 

1 REPLY 1

Re: Calculating rolling slopes

if I understood what you meant by rolling slope, here's a script to do what you're looking for and the secret behind how to make the script.

Script:

dt = Data Table( "Input data" ) << Sort(
	By( :Group, :Minutes ),
	Order( Ascending, Ascending ),
	Output Table( "Sorted Input Data.jmp" )
);

dt << New Table Variable ("window", 5);

dt << new column ("Rolling Slope", numeric, set formula (If( Row() > window,
	(:Reading + Lag( :Reading )) / 2,
	.
)));

Secret (you can skip this if you already know it

If you know how to do things in the GUI in JMP, you don't need a ton of scripting know-how to create the scripts to do things, as you can mostly just copy/paste from the log. Three examples for this script:

1. Sorting. I first sorted the data table using the Tables...Sort command, then I looked at the "Source" script saved to the new data table, and copy/pasted it into a new script window (I did add a "dt = " at the beginning and a semicolon at the end, so you do have to have a tiny bit of scripting know-how).

Jed_Campbell_0-1673018843576.png

2. I added a new table variable using the GUI (red triangle on table, New Table Variable), then I looked at the log and shamelessly copied the script, and pasted it into my script window. I replaced the first part with a reference to "dt".

Jed_Campbell_1-1673018999573.png

3. I typed in "dt << new column ("Rolling Slope", numeric, set formula (xxx));", then I made the formula in the GUI, and copy/pasted it to replace the "xxx" section of code.

Jed_Campbell_2-1673019144346.png

That being said, here's a link to an excellent and free course for learning scripting.