Debian Codegraph @

man/mtable.Rd

raw
1 \name{mtable}
2 \alias{mtable}
3 \alias{relabel.memisc_mtable}
4 \alias{format.memisc_mtable}
5 \alias{print.memisc_mtable}
6 \alias{write.mtable}
7 \alias{toLatex.memisc_mtable}
8 \alias{dim.memisc_mtable}
9 \alias{dimnames.memisc_mtable}
10 \alias{[.memisc_mtable}
11 \alias{c.memisc_mtable}
12
13 \title{Comparative Table of Model Estimates}
14 \description{
15 \code{mtable} produces a table of estimates for several models.
16 }
17 \usage{
18 mtable(\dots,coef.style=getOption("coef.style"),
19 summary.stats=TRUE,
20 signif.symbols=getOption("signif.symbols"),
21 factor.style=getOption("factor.style"),
22 show.baselevel=getOption("show.baselevel"),
23 baselevel.sep=getOption("baselevel.sep"),
24 getSummary=eval.parent(quote(getSummary)),
25 float.style=getOption("float.style"),
26 digits=min(3,getOption("digits")),
27 sdigits=digits,
28 show.eqnames=getOption("mtable.show.eqnames",NA),
29 gs.options=NULL,
30 controls=NULL,
31 collapse.controls=FALSE,
32 control.var.indicator=getOption("control.var.indicator",c("Yes","No"))
33 )
34 \method{relabel}{memisc_mtable}(x, \dots, gsub = FALSE, fixed = !gsub, warn = FALSE)
35
36 \method{format}{memisc_mtable}(x,target=c("print","LaTeX","HTML","delim"),
37 \dots
38 )
39
40 \method{print}{memisc_mtable}(x,
41 center.at=getOption("OutDec"),
42 topsep="=",bottomsep="=",sectionsep="-",\dots)
43
44 write.mtable(object,file="",
45 format=c("delim","LaTeX","HTML"),\dots)
46
47 \method{toLatex}{memisc_mtable}(object,...)
48 }
49 \arguments{
50 \item{\dots}{as argument to \code{mtable}: several model objects, e.g. of class
51 \code{\link{lm}}; as argument to \code{print.memisc_mtable},
52 \code{toLatex.memisc_mtable}, \code{write.memisc_mtable}: further arguments
53 passed to \code{format.memisc_mtable}; as argument to \code{format.memisc_mtable}:
54 further arguments passed to \code{format.default};
55 as argument to \code{relabel.memisc_mtable}: further arguments
56 passed to \code{\link{dimrename}}.
57 }
58 \item{coef.style}{a character string which specifies the style of
59 coefficient values, whether standard errors, Wald/t-statistics,
60 or significance levels are reported, etc. See \code{\link{coef.style}}.}
61 \item{summary.stats}{if \code{FALSE}, no summary statistics
62 are repored. If \code{TRUE} then for each object in \code{\dots}
63 either all summary statistics are reported, or those specified by
64 the option \code{"summary.stats.<cls>"}, where \code{<cls>} is
65 the class of the respective object.
66
67 This argument may also contain a character vector with
68 the names of the summary statistics to report, or a list of
69 character vectors with names of summary statistics for each
70 object passed as argument in \code{\dots}.
71 }
72 \item{signif.symbols}{a named numeric vector to specify
73 the "significance levels" and corresponding symbols.
74 The numeric elements define the significance levels,
75 the attached names define the associated symbols.}
76 \item{factor.style}{a character string that specifies the style in
77 which factor contrasts are labled. See \code{\link{factor.style}}.}
78 \item{show.baselevel}{logical; determines whether base levels of factors are indicated
79 for dummy coefficients}
80 \item{baselevel.sep}{character that is used to separate the base level from the
81 level that a dummy variable represents}
82 \item{getSummary}{a function that computes model-related statistics that
83 appear in the table. See \code{\link{getSummary}}.}
84 \item{float.style}{default format for floating point numbers if
85 no format is specified by \code{coef.style}}.
86 \item{digits}{number of significant digits if not specified by
87 the template returned from \code{\link{getCoefTemplate}}
88 \code{\link{getSummaryTemplate}}
89 }
90 \item{sdigits}{integer; number of digits after decimal dot for
91 summary statistics.}
92 \item{show.eqnames}{logical; if \code{TRUE}, left-hand sides
93 of equations are (always) shown in the table header;
94 if \code{FALSE}, left-hand sides
95 of equations are not shown;
96 if \code{NA}, left-hand sides
97 of equations are shown only if left-hand sides differ
98 among models or one of the models has multiple equations.
99 }
100 \item{gs.options}{an optional list of arguments passed on to
101 \code{getSummary}}
102 \item{controls}{an optional formula or character vector that
103 designates "control variables" for which no coefficients are
104 reported, but only whether they are present in the model.
105 }
106 \item{collapse.controls}{a logical values; should the report about
107 inclusion of control variables collapsed to a single value? If
108 yes, models should either contain none or all of the control
109 variables.
110 }
111 \item{control.var.indicator}{
112 a character vector with to elements; the first element being used
113 to indicate the presence of a control variable or all
114 control variables (if \code{collapse.controls=TRUE}), the second
115 element being used otherwise. By default these elements are
116 \code{"Yes"} and \code{"No"}.
117 }
118 \item{x, object}{an object of class \code{mtable}}
119 \item{gsub, warn, fixed}{logical values, see \code{\link{relabel}}}
120 \item{target}{a character string which indicates the target format.
121 Currenlty the targets
122 "print" (see \code{\link{mtable_format_print}}),
123 "LaTeX" (see \code{\link{mtable_format_latex}}),
124 "HTML" (see \code{\link{mtable_format_html}}), and
125 "delim" (see \code{\link{mtable_format_delim}})
126 are supported.
127 }
128 \item{center.at}{a character string on which resulting values are centered.
129 Typically equal to ".". This is the default when \code{forLaTeX==TRUE}.
130 If \code{NULL}, reported values are not centered.}
131 \item{topsep}{a character string that is recycled to a top rule.}
132 \item{bottomsep}{a character string that is recycled to a bottom rule.}
133 \item{sectionsep}{a character string that is recycled to seperate coefficients
134 from summary statistics.}
135 \item{file}{name of the file where to write to; defaults to console output.}
136 \item{format}{character string that specifies the desired format.}
137 }
138 \details{
139 \code{mtable} constructs a table of estimates for regression-type models.
140 \code{format.memisc_mtable} formats suitable for use with output or conversion functions
141 such as \code{print.memisc_mtable}, \code{toLatex.memisc_mtable}, or
142 \code{write.memisc_mtable}.
143 }
144 \value{
145 A call to \code{mtable} results in an object of class \code{"mtable"}
146 with the following components:
147
148 \item{coefficients}{a list that contains the model coefficients,}
149 \item{summaries}{a matrix that contains the model summaries,}
150 \item{calls}{a list of calls that created the model estimates
151 being summarised.}
152
153 }
154 \examples{
155 #### Basic workflow
156
157 lm0 <- lm(sr ~ pop15 + pop75, data = LifeCycleSavings)
158 lm1 <- lm(sr ~ dpi + ddpi, data = LifeCycleSavings)
159 lm2 <- lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)
160
161 options(summary.stats.lm=c("R-squared","N"))
162 mtable("Model 1"=lm0,"Model 2"=lm1,"Model 3"=lm2)
163
164 options(summary.stats.lm=c("sigma","R-squared","N"))
165 mtable("Model 1"=lm0,"Model 2"=lm1,"Model 3"=lm2)
166
167 options(summary.stats.lm=NULL)
168
169 mtable123 <- mtable("Model 1"=lm0,"Model 2"=lm1,"Model 3"=lm2,
170 summary.stats=c("sigma","R-squared","F","p","N"))
171
172 (mtable123 <- relabel(mtable123,
173 "(Intercept)" = "Constant",
174 pop15 = "Percentage of population under 15",
175 pop75 = "Percentage of population over 75",
176 dpi = "Real per-capita disposable income",
177 ddpi = "Growth rate of real per-capita disp. income"
178 ))
179
180 # This produces output in tab-delimited format:
181 write.mtable(mtable123)
182
183 \dontrun{
184 # This produces output in tab-delimited format:
185 file123 <- "mtable123.txt"
186 write.mtable(mtable123,file=file123)
187 file.show(file123)
188 # The contents of this file can be pasted into Word
189 # and converted into a Word table.
190 }
191 \dontshow{toLatex(mtable123)}
192 \dontrun{texfile123 <- "mtable123.tex"
193 write.mtable(mtable123,format="LaTeX",file=texfile123)
194 file.show(texfile123)}
195
196 #### Examples with UC Berkeley data
197
198 berkeley <- Aggregate(Table(Admit,Freq)~.,data=UCBAdmissions)
199
200 berk0 <- glm(cbind(Admitted,Rejected)~1,data=berkeley,family="binomial")
201 berk1 <- glm(cbind(Admitted,Rejected)~Gender,data=berkeley,family="binomial")
202 berk2 <- glm(cbind(Admitted,Rejected)~Gender+Dept,data=berkeley,family="binomial")
203
204 mtable(berk0,summary.stats=c("Deviance","N"))
205 mtable(berk1,summary.stats=c("Deviance","N"))
206
207 mtable(berk0,berk1,berk2,summary.stats=c("Deviance","N"))
208
209 mtable(berk0,berk1,berk2,
210 coef.style="horizontal",
211 summary.stats=c("Deviance","AIC","N"))
212 mtable(berk0,berk1,berk2,
213 coef.style="stat",
214 summary.stats=c("Deviance","AIC","N"))
215 mtable(berk0,berk1,berk2,
216 coef.style="ci",
217 summary.stats=c("Deviance","AIC","N"))
218 mtable(berk0,berk1,berk2,
219 coef.style="ci.se",
220 summary.stats=c("Deviance","AIC","N"))
221 mtable(berk0,berk1,berk2,
222 coef.style="ci.se.horizontal",
223 summary.stats=c("Deviance","AIC","N"))
224 mtable(berk0,berk1,berk2,
225 coef.style="ci.p.horizontal",
226 summary.stats=c("Deviance","AIC","N"))
227 mtable(berk0,berk1,berk2,
228 coef.style="ci.horizontal",
229 summary.stats=c("Deviance","AIC","N"))
230 mtable(berk0,berk1,berk2,
231 coef.style="all",
232 summary.stats=c("Deviance","AIC","N"))
233 mtable(berk0,berk1,berk2,
234 coef.style="all.nostar",
235 summary.stats=c("Deviance","AIC","N"))
236
237 mtable(by(berkeley,berkeley$Dept,
238 function(x)glm(cbind(Admitted,Rejected)~Gender,
239 data=x,family="binomial")),
240 summary.stats=c("Likelihood-ratio","N"))
241
242
243 mtable(By(~Gender,
244 glm(cbind(Admitted,Rejected)~Dept,
245 family="binomial"),
246 data=berkeley),
247 summary.stats=c("Likelihood-ratio","N"))
248
249 berkfull <- glm(cbind(Admitted,Rejected)~Dept/Gender - 1,
250 data=berkeley,family="binomial")
251 relabel(mtable(berkfull),Dept="Department",gsub=TRUE)
252
253 #### Array-like semantics
254
255 mtable123 <- mtable("Model 1"=lm0,"Model 2"=lm1,"Model 3"=lm2,
256 summary.stats=c("sigma","R-squared","F","p","N"))
257
258 dim(mtable123)
259 dimnames(mtable123)
260 mtable123[c("dpi","ddpi"),
261 c("Model 2","Model 3")]
262
263 #### Concatention
264 mt01 <- mtable(lm0,lm1,summary.stats=c("R-squared","N"))
265 mt12 <- mtable(lm1,lm2,summary.stats=c("R-squared","F","N"))
266 c(mt01,mt12) # not that this makes sense, but ...
267 c("Group 1"=mt01,
268 "Group 2"=mt12)
269 }
270 \keyword{misc}