Hi @Ainaskid
There's probably a million ways to get what you are trying to do. It depends on how you want to give the values of the predictors to get the predicted response. Do you want to do it in a dialog box where the user inputs a number, presses a button, and the window returns a prediction? Would it be acceptable to just put new values of X as additional rows in your data table and have a prediction formula return the predicted value in a column?
I'll show you quickly how to do the latter since it is easier. Here's an example using the Big Class data set and predicting height from weight:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = dt << Bivariate( Y( :height ), X( :weight ), Fit Line() ); //get reference to Bivariate object
rpt = (biv << Report); //get reference to report window for Biv
//get the coefficients from the parameter estimates table
Coefs = (rpt["Parameter Estimates"][Table Box( 1 )] << Get as Matrix)[0, 1];
//Create prediction formula from the coefficients
Eval(
Parse(
Eval Insert( "\[dt << New Column("Prediction Formula", formula(^Coefs[1]^ + ^Coefs[2]^*:weight))]\" )
)
);
//You'll want to hard code in the value of the coefs using the string
//Otherwise this column won't work once Coefs is no longer defined or the value has changed
//The "Eval Insert" function inserts the value of Coefs[1] and Coefs[2] into the formula - this is how it is hard-coded in
Now, you should see a new column in Big Class with the predictions. Since it's a formula, I can add new rows with weight values and get new height predictions. Here, I added a row for 200, and got 75.42 as the prediction
I want to point out that this is even easier if you fit the model in the Fit Model platform instead since you can just send a << Prediction Formula message to the Fit Model object to get the column with the prediction formula.
FitMod = dt << Fit Model(
Y( :height ),
Effects( :weight ),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" ), Run()
);
FitMod << Prediction Formula;
-- Cameron Willden