简体   繁体   English

将值传递给R中的线性回归模型

[英]Passing Values to Linear Regression Model in R

I am new to R and have built a multi linear regression model in R with three predictors now I want to pass value set for the three predictors and predict the value, below are my coefficients and intercept 我是R的新手,并且已经在R中建立了具有三个预测变量的多元线性回归模型,现在我想传递三个预测变量的值集并预测该值,以下是我的系数和截距

(Intercept) XYZ -29 -0.24 3.49 8.3 (拦截)XYZ -29 -0.24 3.49 8.3

I know how to write a formula and manually calculate it, but for example if i want to pass x=0.1 Y is a factor value is '1' and Z=6 to the model and Run the model to get the output how to do that 我知道如何编写公式并手动计算公式,但是例如,如果我要传递x = 0.1 Y是一个因子值,则将'1'和Z = 6传递给模型并运行模型以获取输出该怎么做那

Let's assume your regression object's name is mymod . 假设您的回归对象的名称为mymod Then the predict function has a newdata argument that needs a list supplying named vectors corresponding to the RHS of your formula: 然后, predict函数具有newdata参数,该参数需要一个列表,该列表提供与公式的RHS对应的命名向量:

 predict( mymod, newdata= list(X=0.1, Y='1', Z=6) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM