简体   繁体   English

Matlab / R-具有分类和连续预测变量的线性回归-为什么连续预测变量平方?

[英]Matlab/R - linear regression with categorical & continuous predictors - why is the continuous predictor squared?

I'm doing a linear regression using categorical predictors and a 0 to 1 numerical outcome. 我正在使用分类预测变量和0到1的数字结果进行线性回归。 On this page I saw it suggested to square a numerical predictor when it is alongside a nominal on (see third section on Linear Regression with Categorical Predictor ). 在此页面上,我看到它建议在数值预测变量与标称符号并排时对其求平方(请参阅关于Linear Regression with Categorical Predictor变量的Linear Regression with Categorical Predictor第三部分)。 The example they give (for Matlab, but this generalizes to R as well) is the following formula where weight is continuous and year is nominal: 他们给出的示例(对于Matlab,但这也适用于R)是以下公式,其中weight是连续的, year是标称的:

mdl = fitlm(tbl,'MPG ~ Year + Weight^2')

Is this a universal rule? 这是普遍规则吗? When I do it, I do get much stronger coefficients but I want to make sure I'm not inflating them without warrant. 当我这样做时,我确实得到了更强的系数,但是我想确保我不会在没有认股权证的情况下夸大它们。 Could someone explain the logic of using .^ for numericals alongside categoricals? 有人可以解释使用.^和数字一起使用数字的逻辑吗?

If you graph mpg vs. weight for each year separately and you see curvature then a polynomial in weight might help correct for the non-linearity. 如果分别绘制每年的mpg与重量的关系图,并且看到曲率,则权重的多项式可能有助于校正非线性。

library(lattice)

u <- "https://raw.githubusercontent.com/shifteight/R/master/ISLR/Auto.csv"
Cars <- read.csv(u)

o <- with(Cars, order(year, weight))
xyplot(mpg ~ weight | year, Cars[o, ], type = c("p", "smooth"))

截图

暂无
暂无

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

相关问题 GLM - 使用分类预测器运行简单线性回归时没有 R 平方输出 - GLM - No R-squared output when running simple linear regression with categorical predictor 如何在多重插补中同时使用分类和连续预测变量 [r] - How to use both categorical and continuous predictors in a multiple imputation [r] 具有类别和平方连续变量的R lm交互项 - R lm interaction terms with categorical and squared continuous variables 在具有单个预测变量的线性回归模型中,R平方和调整R平方是否应该相同? - should R-squared and adj.R-squared be the same in a linear regression model with single predictor? 具有类别预测变量的R中的Logistic回归 - Logistic Regression in R with Categorical Predictors 当我们同时具有连续变量和分类变量作为预测变量时,如何在多项逻辑回归中检验多重共线性? - How to test multicollinearity in multinomial logistic regression when we have both continuous variables as well categorical variables as predictors? 可视化连续预测变量与分类结果之间的关系 - Visualizing the relationship between a continuous predictor and a categorical outcome R:“ isat”回归(“ gets”包)中连续和分类变量之间的交互 - R: interaction between continuous and categorical vars in 'isat' regression ('gets' package) 随着我们逐步添加预测变量,获取线性回归模型的R平方值列表 - Get list of R-squared values for linear regression model as we incrementally add predictors 哪种类型的分析具有连续和分类预测因子的分类结果? - What type of analysis with categorical outcome with both continuous and categorical predictors?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM