简体   繁体   English

回归 Model(只有有意义的预测变量的输出)

[英]Regression Model (Outputs with only meaninful predictors)

I have constructed a linear regression model, reg_model1, and the model has factors within it.我已经构建了一个线性回归 model、reg_model1 和 model 中的因素。 However, within the different sets of factors in the model, very few are significant along with other continuous variables.然而,在 model 的不同组因子中,很少有与其他连续变量一起显着的。 Is there any code that one can supply to the reg_model1 to produce a summary that outputs only predictors that best fits the model?是否有任何代码可以提供给 reg_model1 以生成仅输出最适合 model 的预测变量的摘要?

From a statistical point of view I think you are making confusion between independent variables influencing the dependent variable and goodness of fit of the model, so my advice is to be sure about what you are trying to obtain.从统计的角度来看,我认为您在影响因变量的自变量与 model 的拟合优度之间存在混淆,因此我的建议是确定您想要获得的内容。 That said, if you want a representation of your model that only includes some of the variables, you may transform it into a dataframe with broom::tidy :也就是说,如果您想要仅包含一些变量的 model 的表示形式,您可以使用broom::tidy将其转换为 dataframe :

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(broom)

### Create factors ###
mtcars <- mutate(mtcars, across(c(vs, am, gear), as.factor))

lm(mpg ~ disp + vs + am + gear, data=mtcars) |> 
  tidy() |> 
  filter(p.value <= 0.05)
#> # A tibble: 3 × 5
#>   term        estimate std.error statistic      p.value
#>   <chr>          <dbl>     <dbl>     <dbl>        <dbl>
#> 1 (Intercept)  24.7      3.36         7.34 0.0000000865
#> 2 disp         -0.0282   0.00924     -3.05 0.00518     
#> 3 am1           4.67     2.09         2.23 0.0345

Created on 2021-11-20 by the reprex package (v2.0.1)代表 package (v2.0.1) 于 2021 年 11 月 20 日创建

I'd suggest Stepwise Regression / Stepwise Selection.我建议逐步回归/逐步选择。 With this you can choose a best fit based on RSME and the goodness of fit.有了这个,您可以根据 RSME 和拟合优度选择最佳拟合。 Here's a good source performed on mtcars dataset.这是在mtcars数据集上执行的一个很好的来源 There are several other packages which offer pretty much the same thing.还有其他几个包提供几乎相同的东西。 I personally prefer to use step function for this purpose.为此,我个人更喜欢使用步骤 function

step.model <- step(lm(mpg ~ ., mtcars), direction="both", trace=FALSE); 
summary(step.model)

Another stepwise regression R package 'StepReg' you may use,另一个逐步回归 R package 'StepReg' 你可以使用,

For example,例如,

formula <- mpg ~ .
stepwise(formula=formula,
         data=mtcars,
         include="am",
         selection="bidirection",
         select="SL",
         sle=0.15,
         sls=0.15)

暂无
暂无

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

相关问题 在 R 中使用 plm 的没有预测变量的回归模型? - Regression model without predictors using plm in R? statsmodels线性回归-包括模型中所有预测变量的patsy公式 - statsmodels linear regression - patsy formula to include all predictors in model R-如何在回归模型中旋转/互换预测变量(非逐步方法) - R - How to rotate/interchange predictors in a regression model (a not-stepwise approach) R中具有多个虚拟编码预测变量的线性回归模型的箱线图 - Boxplot of Linear Regression Model with several Dummy coded predictors in R 将线性回归 model(&gt; 3 个预测变量)中的两条(!)回归线绘制到具有置信区间(sjPlot 或 ggplot)的相同 plot 中 - Plotting two(!) regression lines from a linear regression model ( > 3 predictors) into the same plot with confidence intervals (sjPlot or ggplot) 在 r 中自定义频率表和回归模型输出 - Customizing frequency tables and regression model outputs in r 可以/我应该使用对数线性模型的输出作为逻辑回归模型中的预测变量吗? - Can/Should I use the output of a log-linear model as the predictors in a logistic regression model? 随着我们逐步添加预测变量,获取线性回归模型的R平方值列表 - Get list of R-squared values for linear regression model as we incrementally add predictors 具有多个预测变量的 R 中的多项式回归 - Polynomial regression in R with multiple predictors 如何在R中进行多因素回归(一般线性模型)而不预先知道预测变量的数量? - How to make a multi-factorial regression (general linear model) in R without knowing in advance the number of predictors?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM