I'm getting stuck on how to take the derivative of the spline fit. The way I have it written, it is pulled straight from the formula but I want to make it more robust. How can I code this to take the derivative of the spline predictor column?
CWfunc = Function({dt_current}, {default local},
//This part of the function creates the crossweb uniformity check//
dt_sub = dt_current;
show(dt_sub);
dt_sub << Select Where(:Panel_RS == "Loop Qual Panel 2");
dt_sub2 = dt_sub << Subset(
Select rows (1),
selected columns only( 0 ),
);
show(dt_sub2);
dt_sub3 = dt_sub2 << Summary(
Group( :Crossweb_LQ, :Loop Lot_LQ ),
Mean( :"Slope(195-250)"n ),
Freq( "None" ),
Weight( "None" ),
Link to original data table( 0 )
);
dt_sub3:"Crossweb_LQ"n << Set Data Type("Numeric");
dt_sub3:"Crossweb_LQ"n << Set Modeling Type("Continuous");
dt_sub4 = dt_sub3 << Bivariate(
Y( :"Mean(Slope(195-250))"n ),
X( :Crossweb_LQ ),
By( :Loop Lot_LQ ),
Fit Spline (100),
//Save Predicteds
);
splinecol = dt_sub4 << (Curve[1] << Save Predicteds);
return(dt_current,dt_sub,dt_sub2,dt_sub3);
);
Derfunc = Function({dt_sub3}, {default local},
dt_sub3 << New Column("Derivative",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula
Num Deriv(Spline Eval(
:Crossweb_LQ,
[1 2.20042178298482 0.057778359275709 0 -0.000683765776914872,
5 2.38777421036511 0.02495760198378 -0.00820518932298666 0.000416694078291779,
9 2.38299001014311 -0.0206825968420827 -0.00320486038348031 0.000748030601767463,
13 2.29685581515222 -0.0104160110250642 0.00577150683773822
-0.0000755519945723868,
17 2.34270055280314 0.0321295479373521 0.00486488290286867 -0.000773631610584581,
21 2.49954444792103 0.0339142938522158 -0.00441869642415559
-0.0000691115769849535,
25 2.56007933961637 -0.00475263323630778 -0.00524803534797586
0.0000699348227685678,
29 2.46157606976071 -0.0433800445272273 -0.00440881747475221
-0.000380207536072129,
33 2.19318152974715 -0.09690054605672 -0.00897130790762231
-0.0000379484318864192,
37 1.65960971935758 -0.170492534048238 -0.0094266890902598 0.00104740989891671,
40 1.09157198267128 0 0 0]
)
);
);
dt_sub3 << New Column(" Pass/Fail",
Character,
Nominal,
);
Return(dt_current,dt_sub,dt_sub2,dt_sub3);
);
Slopefunc = Function({dt_current}, {default local};
dt_sum = dt_current << Summary(
Group( :"Panel Dose (ug/dL)_RS"n, :Loop Lot_LQ, :Foil_LQ ),
Mean( :CW Corrected AR ),
Freq( "None" ),
Weight( "None" )
);
show(dt_sum);
dt_graph = dt_sum <Y( :"Mean(CW Corrected AR)"n ),
X( :"Panel Dose (ug/dL)_RS"n ),
By( :Loop Lot_LQ ),
Group By ( :Foil_LQ ),
);
show(dt_graph);
dt_graph << Fit Line;
return(dt_graph);
);
mainfunc = Function({dt_current}, {defualt local},
output1 = CWfunc(dt_current);
output2 = DerFunc(output1[4]);
output3 = Slopefunc(dt_current);
);