cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
PoissonGopher92
Level III

Loop the derivative function in JSL

Hello JMP user community, I have been struggling for quite some time with a JSL function and wanted to reach out to see if some of you may be able to help.
 
So, what I want the script to do is basically take a formula expression from a polynomial regression model and then build the partial derivatives with respect to each contained factor. Ideally, it would create a list of all the factors contained in the expression formula. And then loop through the list and plug in one factor after another into the derivative function to calculate all the partial derivative formulas and save them separately. The issue is that I can not figure out how I can create such a loop formatting the factor names in a way which is accepted by the derivative function. I already tried a lot, but nothing seems to work. The only two ways that lead to the partial derivative being correctly calculated I attached in the JSL example file.
 
Does anyone have experience with this function, or can help me create the correct input format for the derivative function within the loop? I would greatly appreciate your help!
1 REPLY 1
jthi
Super User

Re: Loop the derivative function in JSL

You could evaluate the item to Derivative

Names Default To Here(1);

formula_expr = Expr(
	48.5137619590147 + -5.01848924914286 * :"Factor 1"n + -6.30434548201033 * :"Factor 2"n
	+4.98953779772742 * :"Factor 3"n + 4.94156314686837 * :"Factor 4"n + -8.10632041659685 *
	:"Factor 5"n + -15.9138137782692 * :"Factor 1"n * :"Factor 1"n + 5.67284677635098 *
	:"Factor 2"n * :"Factor 2"n
);

/////  Working example 1
derivative_expr = Derivative(Name Expr(formula_expr), :Name("Factor 1"));
Show(derivative_expr);

/////  Working example 2
derivative_expr = Derivative(Name Expr(formula_expr), :"Factor 1"n);
Show(derivative_expr);

//// What the loop should look like (not working)
factorList = {:"Factor 1"n, :"Factor 2"n, :"Factor 3"n, :"Factor 4"n, :"Factor 5"n};

For Each({factor_item}, factorList,	
	derivative_expr = Eval(EvalExpr(
		Derivative(Name Expr(formula_expr), Expr(Name Expr(factor_item)));
	));
	Show(derivative_expr);
);
-Jarmo

Recommended Articles