2016-03-02 22 views
0

我對我的數據進行了零膨脹泊松迴歸。我想將回歸的summary()保存在一個整潔的表格中。我試過write.table()和其他變體。大多數錯誤表示它不能解釋彙總輸出。如何從R中的zeroinfl()獲得發佈質量輸出?

下面是我正在嘗試做的一個例子。我標記了不起作用的部分。數據和運行zeroinfl()示例來自http://statistics.ats.ucla.edu/stat/r/dae/zipoisson.html。如何以簡潔的格式保存迴歸模型的摘要?

# This example comes directly from http://statistics.ats.ucla.edu/stat/r/dae/zipoisson.html 

zinb <- read.csv("http://www.ats.ucla.edu/stat/data/fish.csv") 
zinb <- within(zinb, { 
    nofish <- factor(nofish) 
    livebait <- factor(livebait) 
    camper <- factor(camper) 
}) 

summary(m1 <- zeroinfl(count ~ child + camper | persons, data = zinb)) 

#my code for writing the output 
write.table(x=summary(m1), file="summary_m1.csv") # this doesn't work 
htmlreg(summary(m1), digits=3, file="summary_m1.html") # this doesn't work 
+1

看看明星包。 –

+0

也可能是'pkg:ReporteRs',看看https://cran.r-project.org/web/views/ReproducibleResearch.html –

回答

2
require(pscl) 
summary(m1 <- zeroinfl(count ~ child + camper | persons, data = zinb)) 

Call: 
zeroinfl(formula = count ~ child + camper | persons, data = zinb) 

Pearson residuals: 
    Min  1Q Median  3Q  Max 
-1.2369 -0.7540 -0.6080 -0.1921 24.0847 

Count model coefficients (poisson with log link): 
      Estimate Std. Error z value Pr(>|z|)  
(Intercept) 1.59789 0.08554 18.680 <2e-16 *** 
child  -1.04284 0.09999 -10.430 <2e-16 *** 
camper1  0.83402 0.09363 8.908 <2e-16 *** 

Zero-inflation model coefficients (binomial with logit link): 
      Estimate Std. Error z value Pr(>|z|)  
(Intercept) 1.2974  0.3739 3.470 0.000520 *** 
persons  -0.5643  0.1630 -3.463 0.000534 *** 
--- 
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 12 
Log-likelihood: -1032 on 5 Df 

應用到模型對象的斯塔蓋澤的`結果可以被傳遞到一個乳膠 「容器」:

> stargazer(m1) # Latex is default but type="html" is also possible 
# returns ------ 

% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu 
% Date and time: Wed, Mar 02, 2016 - 12:37:08 
\begin{table}[!htbp] \centering 
    \caption{} 
    \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
& \multicolumn{1}{c}{\textit{Dependent variable:}} \\ 
\cline{2-2} 
\\[-1.8ex] & count \\ 
\hline \\[-1.8ex] 
child & $-$1.043$^{***}$ \\ 
    & (0.100) \\ 
    & \\ 
camper1 & 0.834$^{***}$ \\ 
    & (0.094) \\ 
    & \\ 
Constant & 1.598$^{***}$ \\ 
    & (0.086) \\ 
    & \\ 
\hline \\[-1.8ex] 
Observations & 250 \\ 
Log Likelihood & $-$1,031.608 \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:} & \multicolumn{1}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 

在MacTEX都成功膠乳代碼:

\documentclass{article} 
\usepackage{tikz} 
\usepackage{verbatim} 

\begin{document} 
\pagestyle{empty} 
% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu 
% Date and time: Wed, Mar 02, 2016 - 12:39:08 
\begin{table}[!htbp] \centering 
    \caption{} 
    \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
& \multicolumn{1}{c}{\textit{Dependent variable:}} \\ 
\cline{2-2} 
\\[-1.8ex] & count \\ 
\hline \\[-1.8ex] 
child & $-$1.043$^{***}$ \\ 
    & (0.100) \\ 
    & \\ 
camper1 & 0.834$^{***}$ \\ 
    & (0.094) \\ 
    & \\ 
Constant & 1.598$^{***}$ \\ 
    & (0.086) \\ 
    & \\ 
\hline \\[-1.8ex] 
Observations & 250 \\ 
Log Likelihood & $-$1,031.608 \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:} & \multicolumn{1}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 

\end{document} 

enter image description here

+0

或者,使用'memisc'中的'mtable()',我個人發現它更多模塊化和直覺比'觀星者'。 –