代码之家  ›  专栏  ›  技术社区  ›  Lumos

回归输出的索引变量

  •  0
  • Lumos  · 技术社区  · 7 年前

    在我从回归中获得输出后,是否有任何方法可以在此回归模型中为某些变量编制索引?

    E、 g.回归

     myModel <- lm(y ~ a*b+c)
     myModelSumm <- summary(myModel)
     varNeeded <- myModelSumm$...
     print(varNeeded) = c
    

    如何在输出中索引变量c?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Patrik_P    7 年前

    如果要从 summary 函数可以使用简单的行-列索引。比方说,我对汽车包装中的Prestige数据集中的教育变量感兴趣。更具体地说,您希望索引出教育变量:

    data("Prestige", package="car") #load the Prestige dataset from the car package
    modelPrestige <- lm(prestige~education*income+type, data=Prestige) #run the regression
    summary(modelPrestige)$coefficients["education",] #index education from the coefficients´ table
    #    Estimate   Std. Error      t value     Pr(>|t|) 
    #5.104321e+00 7.766489e-01 6.572237e+00 2.933852e-09 
    

    此外,您还可以提取Instance的估计时间:

    summary(modelPrestige)$coefficients["education",]["Estimate"]
    #Estimate 
    #5.104321 
    

    如果出于任何原因,您的兴趣是真|假向量,您可以使用:

    rownames(summary(modelPrestige)$coefficients) == "education"
    #[1] FALSE  TRUE FALSE FALSE FALSE FALSE
    

    希望这有帮助!