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
%3CLINGO-SUB%20id%3D%22lingo-sub-615040%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20calculate%20area%20under%20the%20curve%20by%20integration%20then%20populate%20the%20result%20in%20a%20new%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-615040%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ETry%20checking%20out%20how%20the%20formula%20JMP%20generates%20does%20look%20like%2C%20it%20will%20most%20likely%20replace%20your%20time%20with%20%3Atime%20so%20use%20different%20name%20for%20the%20variable%20and%20inside%20expression%20than%20columns%20in%20your%20data%20table%20(and%20possibly%20wrap%20it%20inside%20As%20Constant())%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EAs%20Constant(%0A%20resp%20%3D%20Expr(a%20*%20a)%3B%0A%20area%20%3D%20Integrate(resp%2C%20a%2C%20Col%20Min(%3Atime)%2C%20Col%20Max(%3Atime))%3B%0A)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-615213%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20calculate%20area%20under%20the%20curve%20by%20integration%20then%20populate%20the%20result%20in%20a%20new%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-615213%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EWhat%20if%20the%20expression%20used%20by%20Integrate%20needs%20to%20be%20extracted%20from%20the%20formula%20in%20a%20column%2C%20for%20example%20to%20Integrate%20using%20a%20formula%20from%20a%20polynomial%20fit.%3C%2FP%3E%3CP%3EIn%20the%20table%20below%2C%20the%20formula%20in%20the%20predictor%20column%20would%20use%26nbsp%3B%26nbsp%3B%3Atime%20and%20%3Aresponse.%20Is%20there%20a%20quick%20syntax%20to%20replace%20the%20column%20names%20with%20new%20variables%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F51369iE64A7D6BF48830D5%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22GroupSquareWolf_0-1679436129378.png%22%20alt%3D%22GroupSquareWolf_0-1679436129378.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-615282%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20calculate%20area%20under%20the%20curve%20by%20integration%20then%20populate%20the%20result%20in%20a%20new%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-615282%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EI%20wouldn't%20use%20formulas%20if%20you%20just%20want%20to%20replicate%20same%20value%20to%20each%20row%20(in%20most%20cases%20it%20is%20better%20to%20use%20%26lt%3B%26lt%3B%20Set%20Each%20Value%20in%20cases%20like%20this).%3C%2FP%3E%0A%3CP%3EI'm%20not%20sure%20if%20there%20is%20any%20quick%20syntax%20to%20replace%20column%20names%20with%20new%20variables%2C%20but%20char%2Bsubstitute%2Bparse%2Bexpressions%20is%20one%20option%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0A%0Adt%20%3D%20New%20Table(%22Untitled%22%2C%0A%20Add%20Rows(4)%2C%0A%20Compress%20File%20When%20Saved(1)%2C%0A%20New%20Column(%22t%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Set%20Values(%5B1%2C%202%2C%203%2C%204%5D))%2C%0A%20New%20Column(%22r%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Formula(%3At%20%5E%202))%0A)%3B%0A%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22i%22%2C%20Numeric%2C%20Continuous%2C%20%26lt%3B%26lt%3B%20Set%20Each%20Value(%0A%20f%20%3D%20Eval%20Expr(Expr(Parse(Substitute(Char(Column(dt%2C%20%22r%22)%20%26lt%3B%26lt%3B%20get%20formula)%2C%20%22%3A%22%2C%20%22%22))))%3B%0A%20Integrate(f%2C%20t%2C%20Col%20Min(%3At)%2C%20Col%20Max(%3At))%3B%0A))%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-615023%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3Ecalculate%20area%20under%20the%20curve%20by%20integration%20then%20populate%20the%20result%20in%20a%20new%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-615023%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIn%20this%20example%20datatable%2C%20response%20is%20defined%20by%20fomula%3A%26nbsp%3B%20response%20%3D%20time*time%3C%2FP%3E%3CP%3EI%20would%20like%20to%20calculate%20%22area%20under%20the%20curve%22%20(AUC)%20by%20integration%20using%20the%20fomula%20defined%20in%20the%20response%20column%20and%20the%20time%20range%20defined%20in%20the%20%3Atime%20column%2C%26nbsp%3Bthen%20populate%20the%20result%20in%20a%20new%20column%20in%20the%20datatable%20(by%20%22populate%22%20I%20mean%20all%20rows%20have%20the%20value%20of%20the%20calculated%20AUC).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20know%20I%20can%20use%20the%20following%20script%20to%20calculate%20the%20AUC%2C%20and%20the%20result%20of%20area%20is%2041333.%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Eresp%20%3D%20Expr%20(time%20*%20time)%3B%0A%0Aarea%20%3D%20Integrate%20(resp%2C%20time%2C%2010%2C%2050)%3B%0A%0Ashow%20(area)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EHowever%2C%20when%20I%20tried%20to%20populate%20the%20AUC%20result%20(all%20rows%20have%20the%20value%20of%2041333)%3CSPAN%3E%26nbsp%3Bin%20the%20%3AIntegrate%20column%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3Bby%20using%20formula%3A%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Integrate(%20%3Aresponse%2C%20%3Atime%2C%20Col%20Maximum(%20%3Atime%20)%2C%20Col%20Minimum(%20%3Atime%20)%20)%3C%2FP%3E%3CP%3Einstead%20of%20populating%20the%20result%2041333%20%2C%20the%20formula%20calculated%20the%20result%20based%20on%20the%20defined%26nbsp%3Bvalue%20of%20%3A%20time%20in%20each%20row.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20is%20the%20correct%20way%20to%20write%20the%20formula%20so%20that%20the%20%3AIntegrate%20column%20is%20populated%20with%20the%20result%2041333%3F%3C%2FP%3E%3CP%3EI%20know%20I%20could%20use%20JSL%20to%20create%20a%20new%20datatable%20and%20then%20join%20the%20result%20but%20would%20prefer%20to%20do%20this%20within%20the%20same%20datatable.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22GroupSquareWolf_0-1679416641928.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679416641928.png%22%20style%3D%22width%3A%20293px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22GroupSquareWolf_0-1679416641928.png%22%20style%3D%22width%3A%20293px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F51343i47B15125FBF81FE5%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22GroupSquareWolf_0-1679416641928.png%22%20alt%3D%22GroupSquareWolf_0-1679416641928.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-615023%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3EAutomation%20and%20Scripting%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Choose Language Hide Translation Bar
GroupSquareWolf
Level III

calculate area under the curve by integration then populate the result in a new column.

In this example datatable, response is defined by fomula:  response = time*time

I would like to calculate "area under the curve" (AUC) by integration using the fomula defined in the response column and the time range defined in the :time column, then populate the result in a new column in the datatable (by "populate" I mean all rows have the value of the calculated AUC).

 

I know I can use the following script to calculate the AUC, and the result of area is 41333.

resp = Expr (time * time);

area = Integrate (resp, time, 10, 50);

show (area);

However, when I tried to populate the AUC result (all rows have the value of 41333) in the :Integrate column by using formula: 

      Integrate( :response, :time, Col Maximum( :time ), Col Minimum( :time ) )

instead of populating the result 41333 , the formula calculated the result based on the defined value of : time in each row. 

 

What is the correct way to write the formula so that the :Integrate column is populated with the result 41333?

I know I could use JSL to create a new datatable and then join the result but would prefer to do this within the same datatable.

 

Thanks!

 

GroupSquareWolf_0-1679416641928.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: calculate area under the curve by integration then populate the result in a new column.

I wouldn't use formulas if you just want to replicate same value to each row (in most cases it is better to use << Set Each Value in cases like this).

I'm not sure if there is any quick syntax to replace column names with new variables, but char+substitute+parse+expressions is one option

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(4),
	Compress File When Saved(1),
	New Column("t", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4])),
	New Column("r", Numeric, "Continuous", Format("Best", 12), Formula(:t ^ 2))
);

dt << New Column("i", Numeric, Continuous, << Set Each Value(
	f = Eval Expr(Expr(Parse(Substitute(Char(Column(dt, "r") << get formula), ":", ""))));
	Integrate(f, t, Col Min(:t), Col Max(:t));
));
-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: calculate area under the curve by integration then populate the result in a new column.

Try checking out how the formula JMP generates does look like, it will most likely replace your time with :time so use different name for the variable and inside expression than columns in your data table (and possibly wrap it inside As Constant())

As Constant(
	resp = Expr(a * a);
	area = Integrate(resp, a, Col Min(:time), Col Max(:time));
)
-Jarmo
GroupSquareWolf
Level III

Re: calculate area under the curve by integration then populate the result in a new column.

What if the expression used by Integrate needs to be extracted from the formula in a column, for example to Integrate using a formula from a polynomial fit.

In the table below, the formula in the predictor column would use  :time and :response. Is there a quick syntax to replace the column names with new variables?

 

GroupSquareWolf_0-1679436129378.png

 

jthi
Super User

Re: calculate area under the curve by integration then populate the result in a new column.

I wouldn't use formulas if you just want to replicate same value to each row (in most cases it is better to use << Set Each Value in cases like this).

I'm not sure if there is any quick syntax to replace column names with new variables, but char+substitute+parse+expressions is one option

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(4),
	Compress File When Saved(1),
	New Column("t", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4])),
	New Column("r", Numeric, "Continuous", Format("Best", 12), Formula(:t ^ 2))
);

dt << New Column("i", Numeric, Continuous, << Set Each Value(
	f = Eval Expr(Expr(Parse(Substitute(Char(Column(dt, "r") << get formula), ":", ""))));
	Integrate(f, t, Col Min(:t), Col Max(:t));
));
-Jarmo