简体   繁体   English

在R中:如何在交互的预测变量上运行多元线性回归,而不对未交互的变量进行回归?

[英]In R: How do I run a multiple linear regression on interacted predictors without regressing on the variables not interacted?

For the life of me I cannot figure out how to run a multiple linear regression with two predictors interacted without also regressing on the interacted predictors by themselves. 在我的一生中,我无法弄清楚如何在两个预测变量相互影响的情况下运行多元线性回归,而又不自行对交互的预测变量进行回归。 Here is an example: 这是一个例子:

When I use this script to do a regression 当我使用此脚本进行回归时

lagfit <- lm(formula = Production ~ DayOfWeek*Employees, data = train)

It returns a regression with three predictors: day of week, # of employees, and the interaction. 它返回具有三个预测变量的回归:星期几,员工人数和互动。 But I only want to regress on the interaction. 但是我只想在互动上回归。 How can I do this? 我怎样才能做到这一点?

您可以只使用:运算符代替*

lagfit <- lm(formula = Production ~ DayOfWeek:Employees, data = train)

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

相关问题 如何在 R 循环中更改线性回归中的预测变量? - How do I change predictors in linear regression in loop in R? 如何使用向量作为我的预测变量来运行多元线性回归? - How do I run a multiple linear regression using a vector as my predictors? 多个交叉/交互列上的 R 列联表 - R contingency table on multiple crossed/interacted columns 如何在R中进行多因素回归(一般线性模型)而不预先知道预测变量的数量? - How to make a multi-factorial regression (general linear model) in R without knowing in advance the number of predictors? 如何为多个不同的响应和预测变量运行分段线性回归,其中响应在不同的时间开始? - How to run piecewise linear regression for multiple different responses and predictors, where responses start at different times? 在 R 中使用带有二次项和交互虚拟变量的边距命令 - Using margins command in R with quadratic term and interacted dummy variables 在R中的data.table中创建复合/交互虚拟变量 - Creating compound/interacted dummy variables in data.table in R 通过R中线性回归的两个预测变量组合 - By two combinations of predictors in linear regression in R 具有多个预测变量的 R 中的多项式回归 - Polynomial regression in R with multiple predictors 如何使用循环在 R 中使用不同变量运行回归? - How do I run a regression with different variables in R using a loop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM