【发布时间】:2021-06-11 22:38:07
【问题描述】:
我是 R、编码和 Stack Overflow 的新手:如果这是一个基本问题,请提前道歉。我正在尝试将变量“性别”的 3 个级别的回归输出组合到一个汇总表中,该汇总表保留了列中的所有信息以及值(残差、r2、调整后的 r2、F 统计量、 p 值)列在每个输出的底部。有人知道可行的方法吗?
这是我的输出当前的样子:
library(tidyverse)
Final_Frame.df <- read_csv("indirect.csv")
my.fun <- function(Final_Frame2.df){summary(lm(Product_Use~Mean_social_combined +
Mean_traditional_time+
Mean_Passive_Use_Updated+
Mean_Active_Use_Updated, data=Final_Frame.df))}
by(Final_Frame.df, list(Final_Frame.df$Gender), my.fun)
输出
Call:
lm(formula = Product_Use ~ Mean_social_combined + Mean_traditional_time +
Mean_Passive_Use_Updated + Mean_Active_Use_Updated, data = Final_Frame.df)
Residuals:
Min 1Q Median 3Q Max
-26.592 -8.178 -3.936 6.228 62.258
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.5814 1.9664 -0.296 0.767612
Mean_social_combined 2.4961 1.1797 2.116 0.034906 *
Mean_traditional_time 1.0399 0.7416 1.402 0.161567
Mean_Passive_Use_Updated 2.8230 0.8308 3.398 0.000739 ***
Mean_Active_Use_Updated 2.7562 1.7421 1.582 0.114329
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 12.07 on 451 degrees of freedom
(18 observations deleted due to missingness)
Multiple R-squared: 0.1517, Adjusted R-squared: 0.1442
F-statistic: 20.17 on 4 and 451 DF, p-value: 2.703e-15
---------------------------------------------------------------------------------------------
: 2
Call:
lm(formula = Product_Use ~ Mean_social_combined + Mean_traditional_time +
Mean_Passive_Use_Updated + Mean_Active_Use_Updated, data = Final_Frame.df)
Residuals:
Min 1Q Median 3Q Max
-26.592 -8.178 -3.936 6.228 62.258
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.5814 1.9664 -0.296 0.767612
Mean_social_combined 2.4961 1.1797 2.116 0.034906 *
Mean_traditional_time 1.0399 0.7416 1.402 0.161567
Mean_Passive_Use_Updated 2.8230 0.8308 3.398 0.000739 ***
Mean_Active_Use_Updated 2.7562 1.7421 1.582 0.114329
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 12.07 on 451 degrees of freedom
(18 observations deleted due to missingness)
Multiple R-squared: 0.1517, Adjusted R-squared: 0.1442
F-statistic: 20.17 on 4 and 451 DF, p-value: 2.703e-15
---------------------------------------------------------------------------------------------
: 3
Call:
lm(formula = Product_Use ~ Mean_social_combined + Mean_traditional_time +
Mean_Passive_Use_Updated + Mean_Active_Use_Updated, data = Final_Frame.df)
Residuals:
Min 1Q Median 3Q Max
-26.592 -8.178 -3.936 6.228 62.258
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.5814 1.9664 -0.296 0.767612
Mean_social_combined 2.4961 1.1797 2.116 0.034906 *
Mean_traditional_time 1.0399 0.7416 1.402 0.161567
Mean_Passive_Use_Updated 2.8230 0.8308 3.398 0.000739 ***
Mean_Active_Use_Updated 2.7562 1.7421 1.582 0.114329
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 12.07 on 451 degrees of freedom
(18 observations deleted due to missingness)
Multiple R-squared: 0.1517, Adjusted R-squared: 0.1442
F-statistic: 20.17 on 4 and 451 DF, p-value: 2.703e-15
【问题讨论】:
-
看看
ddply,类似:ddply( Final_Frame.df, 'Gender', function(d) { create_the_data_frame_you_need() } )# 在函数体中,您可以访问d,这是您的每个唯一值的数据的子集 Gender -
为了让我们帮助您,请编辑您的问题以包含reproducible example。例如,要生成最小数据集,您可以使用
head()、subset()或索引。然后使用dput()给我们一些可以立即放入R 的东西。另外,请确保您知道该怎么做when someone answers your question。更多信息可以在 StackOverflow 的help center 找到。谢谢!
标签: r merge output concatenation linear-regression