首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否为slidify生成回归表?

是否为slidify生成回归表?
EN

Stack Overflow用户
提问于 2014-07-01 22:45:25
回答 1查看 142关注 0票数 0

为slidify生成美观的回归表的最佳方式是什么?

代码语言:javascript
复制
---
## Custom Tables

```{r, results = "asis", echo = FALSE}

库(Xtable)

OLS <- lm(hp ~ wt,mtcar)

打印(xtable(OLS),type="html",html.table.properties=‘class=mytable’,label ="OLS",digits = 3)

代码语言:javascript
复制
<style>
table.mytable {
  border: none;
  width: 100%;
  border-collapse: collapse;
  font-size: 45px;
  line-height: 50px;
  font-family: 'Ubuntu';'Trebuchet MS';
  font-weight: bolder;
  color: blue;
}

table.mytable tr:nth-child(2n+1) {
/*  background: #E8F2FF; */
  background: #FFFFFF;
}
</style>

我希望能够更改名称('Constant‘而不是Intercept,'Weight’代替wt),添加观察值数量,R平方,F统计量等。

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2015-02-09 17:42:39

第一,

代码语言:javascript
复制
# Check what's inside your OLS object:
names(OLS)
 [1] "coefficients" 
 [2] "residuals"    
 [3] "effects"      
 [4] "rank"         
 [5] "fitted.values"
 [6] "assign"       
 [7] "qr"           
 [8] "df.residual"  
 [9] "xlevels"      
[10] "call"         
[11] "terms"        
[12] "model"        

# Look inside coeff:
names(OLS$coeff)
[1] "(Intercept)"
[2] "wt"         

# Rename:
names(OLS$coeff) <- c("Constant", "Weight")

# Check the new names:
names(OLS$coeff)
[1] "Constant" "Weight"

其次,可以用类似的方法求出R平方

代码语言:javascript
复制
summary(OLS)

Call:
lm(formula = hp ~ wt, data = mtcars)

Residuals:
    Min      1Q  Median 
-83.430 -33.596 -13.587 
     3Q     Max 
  7.913 172.030 

Coefficients:
            Estimate
(Intercept)   -1.821
wt            46.160
            Std. Error
(Intercept)     32.325
wt               9.625
            t value Pr(>|t|)
(Intercept)  -0.056    0.955
wt            4.796 4.15e-05

(Intercept)    
wt          ***
---
Signif. codes:  
  0 ‘***’ 0.001 ‘**’ 0.01
  ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 52.44 on 30 degrees of freedom
Multiple R-squared:  0.4339,    Adjusted R-squared:  0.4151 
F-statistic:    23 on 1 and 30 DF,  p-value: 4.146e-05

您可以通过str(summary(OLS))查看更多信息。因此:

代码语言:javascript
复制
 summary(OLS)$r.squared
[1] 0.4339488
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24513150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档