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%3EBetreff%3A%20Berechnen%20Sie%20die%20Fl%C3%A4che%20unter%20der%20Kurve%20durch%20Integration%20und%20f%C3%BCllen%20Sie%20das%20Ergebnis%20in%20einer%20neuen%20Spalte%20aus.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-615040%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EVersuchen%20Sie%20herauszufinden%2C%20wie%20die%20von%20JMP%20generierte%20Formel%20aussieht.%20Sie%20wird%20h%C3%B6chstwahrscheinlich%20Ihre%20Zeit%20durch%20%3Atime%20ersetzen.%20Verwenden%20Sie%20also%20einen%20anderen%20Namen%20f%C3%BCr%20die%20Variable%20und%20den%20inneren%20Ausdruck%20als%20die%20Spalten%20in%20Ihrer%20Datentabelle%20(und%20wickeln%20Sie%20sie%20m%C3%B6glicherweise%20in%20As%20Constant()%20ein).%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%3EBetreff%3A%20Berechnen%20Sie%20die%20Fl%C3%A4che%20unter%20der%20Kurve%20durch%20Integration%20und%20f%C3%BCllen%20Sie%20das%20Ergebnis%20in%20einer%20neuen%20Spalte%20aus.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-615213%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EWas%20ist%2C%20wenn%20der%20von%20Integrate%20verwendete%20Ausdruck%20aus%20der%20Formel%20in%20einer%20Spalte%20extrahiert%20werden%20muss%2C%20um%20beispielsweise%20mithilfe%20einer%20Formel%20aus%20einer%20Polynomanpassung%20zu%20integrieren%3F%3C%2FP%3E%3CP%3EIn%20der%20folgenden%20Tabelle%20w%C3%BCrde%20die%20Formel%20in%20der%20Pr%C3%A4diktorspalte%20%3Atime%20und%20%3Aresponse%20verwenden.%20Gibt%20es%20eine%20schnelle%20Syntax%2C%20um%20die%20Spaltennamen%20durch%20neue%20Variablen%20zu%20ersetzen%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%3EBetreff%3A%20Berechnen%20Sie%20die%20Fl%C3%A4che%20unter%20der%20Kurve%20durch%20Integration%20und%20f%C3%BCllen%20Sie%20das%20Ergebnis%20in%20einer%20neuen%20Spalte%20aus.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-615282%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIch%20w%C3%BCrde%20keine%20Formeln%20verwenden%2C%20wenn%20Sie%20nur%20denselben%20Wert%20in%20jede%20Zeile%20replizieren%20m%C3%B6chten%20(in%20den%20meisten%20F%C3%A4llen%20ist%20es%20in%20solchen%20F%C3%A4llen%20besser%2C%20%26lt%3B%26lt%3B%20Set%20Each%20Value%20zu%20verwenden).%3C%2FP%3E%0A%3CP%3EIch%20bin%20mir%20nicht%20sicher%2C%20ob%20es%20eine%20schnelle%20Syntax%20gibt%2C%20um%20Spaltennamen%20durch%20neue%20Variablen%20zu%20ersetzen%2C%20aber%20char%2Bsubstitute%2Bparse%2Bexpressions%20ist%20eine%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%3EBerechnen%20Sie%20die%20Fl%C3%A4che%20unter%20der%20Kurve%20durch%20Integration%20und%20tragen%20Sie%20das%20Ergebnis%20dann%20in%20eine%20neue%20Spalte%20ein.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-615023%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIn%20dieser%20Beispieldatentabelle%20wird%20die%20Antwort%20durch%20die%20Formel%20definiert%3A%20Antwort%20%3D%20Zeit*Zeit%3C%2FP%3E%3CP%3EIch%20m%C3%B6chte%20die%20%E2%80%9EFl%C3%A4che%20unter%20der%20Kurve%E2%80%9C%20(AUC)%20durch%20Integration%20mithilfe%20der%20in%20der%20Antwortspalte%20definierten%20Formel%20und%20des%20in%20der%20Spalte%20%E2%80%9E%3Atime%E2%80%9C%20definierten%20Zeitbereichs%20berechnen%20und%20das%20Ergebnis%20dann%20in%20eine%20neue%20Spalte%20in%20der%20Datentabelle%20f%C3%BCllen%20(durch%20%E2%80%9Epopulate%20%E2%80%9EIch%20meine%2C%20alle%20Zeilen%20haben%20den%20Wert%20der%20berechneten%20AUC).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIch%20wei%C3%9F%2C%20dass%20ich%20das%20folgende%20Skript%20verwenden%20kann%2C%20um%20die%20AUC%20zu%20berechnen%2C%20und%20das%20Ergebnis%20der%20Fl%C3%A4che%20ist%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%3EAls%20ich%20jedoch%20versuchte%2C%20das%20AUC-Ergebnis%20auszuf%C3%BCllen%20(alle%20Zeilen%20haben%20den%20Wert%2041333)%3CSPAN%3E%20in%20der%20Spalte%20%3AIntegrieren%3C%2FSPAN%3E%3CSPAN%3E%20mit%20der%20Formel%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EIntegrieren(%20%3Aresponse%2C%20%3Atime%2C%20Col%20Maximum(%20%3Atime%20)%2C%20Col%20Minimum(%20%3Atime%20)%20)%3C%2FP%3E%3CP%3EAnstatt%20das%20Ergebnis%2041333%20auszuf%C3%BCllen%2C%20berechnete%20die%20Formel%20das%20Ergebnis%20basierend%20auf%20dem%20definierten%20Wert%20von%3A%20Zeit%20in%20jeder%20Zeile.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWie%20schreibe%20ich%20die%20Formel%20richtig%2C%20damit%20die%20Spalte%20%E2%80%9E%3AIntegrate%E2%80%9C%20mit%20dem%20Ergebnis%2041333%20gef%C3%BCllt%20wird%3F%3C%2FP%3E%3CP%3EIch%20wei%C3%9F%2C%20dass%20ich%20JSL%20verwenden%20k%C3%B6nnte%2C%20um%20eine%20neue%20Datentabelle%20zu%20erstellen%20und%20dann%20das%20Ergebnis%20zu%20verkn%C3%BCpfen%2C%20w%C3%BCrde%20dies%20aber%20lieber%20innerhalb%20derselben%20Datentabelle%20tun.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDanke!%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%3EAutomatisierung%20und%20Skripterstellung%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