我目前第一次使用 JSL 来自动化数据分析/报告。 我的分析涉及:
1.导入所需数据(完成)
2. 分析数据(data)
3. 使用计算数据执行双变量分析并拟合直线(完成)
4. 使用生成的回归方程来预测特定“y”值的“x”:这就是我的问题所在。 我希望能够在 JSL 中从“y”动态生成“x”。 我也不想手动输入回归方程,因为这对于不同的数据集会有所不同。
有什么指点吗?
这使用拟合曲线平台并保存具有逆预测的公式列。
dt=open("$Sample_Data/Big Class.jmp");
model= Fit Curve( Y( :height ), X( :weight ) );
model<< Fit Linear(Save Inverse Prediction Formula);
您可以只使用表中的值,但也可以获取公式列属性,
我应该要求澄清。你真的想做逆向预测吗?如果是这样,您仍然可以使用我的方法,只需使用 (:height - coef[1])/coef[2] 执行公式
最简单的方法可能是使用拟合模型并获取内置逆预测的拟合最小二乘平台。
你好@艾纳斯基德
可能有一百万种方法可以实现您想要做的事情。这取决于您想要如何给出预测变量的值以获得预测响应。您想在用户输入数字、按下按钮、窗口返回预测的对话框中执行此操作吗?将 X 的新值作为附加行放入数据表中并让预测公式在列中返回预测值是否可以接受?
我将快速向您展示如何执行后者,因为它更容易。以下是使用 Big Class 数据集并根据体重预测身高的示例:
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
现在,您应该会在 Big Class 中看到一个包含预测的新列。由于它是一个公式,我可以添加带有重量值的新行并获得新的高度预测。在这里,我添加了一行 200,得到了 75.42 作为预测
我想指出,如果您在“拟合模型”平台中拟合模型,这会更容易,因为您只需向“拟合模型”对象发送 << 预测公式消息即可获取包含预测公式的列。
FitMod = dt << Fit Model(
Y( :height ),
Effects( :weight ),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" ), Run()
);
FitMod << Prediction Formula;