Codebase list hmisc / upstream/3.14-6
Import Upstream version 3.14-6 Dirk Eddelbuettel 5 years ago
21 changed file(s) with 249 addition(s) and 116 deletion(s). Raw diff Collapse all Expand all
00 Package: Hmisc
1 Version: 3.14-5
2 Date: 2014-09-11
1 Version: 3.14-6
2 Date: 2014-11-16
33 Title: Harrell Miscellaneous
44 Author: Frank E Harrell Jr <f.harrell@vanderbilt.edu>, with
55 contributions from Charles Dupont and many others.
1717 LazyLoad: Yes
1818 URL: http://biostat.mc.vanderbilt.edu/Hmisc,
1919 https://github.com/harrelfe/Hmisc
20 Packaged: 2014-09-11 21:00:20 UTC; harrelfe
20 Packaged: 2014-11-21 18:05:11 UTC; harrelfe
2121 NeedsCompilation: yes
2222 Repository: CRAN
23 Date/Publication: 2014-09-12 15:50:33
23 Date/Publication: 2014-11-22 00:42:24
+20
-20
MD5 less more
00 16f8ea43efba90112351c5ecb33021c4 *COPYING
1 28b724e3db7594714c1ab685e1b877f3 *DESCRIPTION
1 3c38884e849267c86148b87c6e843631 *DESCRIPTION
22 17da8e77284bb353c8e685a3c47a669d *INDEX
3 6b76cfc1cd8c7205a7a46f26c3a2f18d *NAMESPACE
4 716a51594604fcc74f0aa34a8ca7a118 *NEWS
3 a8b838ef66b469e2b6ae849e3f96f74a *NAMESPACE
4 57f1318c607746fb3bd8c6ec3c4a9c11 *NEWS
55 76f90acbe9bf8ad2eaaa6b8813eb7c82 *R/AFirst.lib.s
66 62ef16fc333551d6c65f15dedfb5a697 *R/Cs.s
77 387ca68eeb2830ad1d19cdbd979cef6e *R/Key.s
2121 8c002470a851e0d14571cfda085e6c42 *R/confbar.s
2222 1274fe9b36deb504e596de1fc99cdbcb *R/consolidate.s
2323 c04e31869fdc5107eb6af6886eadb566 *R/cpower.s
24 a0d62412137930c872a577dc5ea139c2 *R/curveRep.s
24 45de10ab5edf3d2a193a8617fe6128f4 *R/curveRep.s
2525 5da6635f342086cedeee652e296ce9e1 *R/cut2.s
2626 25c501e1db065dacd0b7ebbc9918254e *R/data.frame.labelled.s
2727 97dc5dcc48cb719088b817833067352c *R/dataRep.s
2828 8ef7d2efc9aa8c82dcdb3073d48477ae *R/dates.s
2929 3f02d2486d14e095a96fe5ee10e483c7 *R/deff.s
30 1e1f95133698fda2a768f668e276e98d *R/describe.s
30 c836746571a4ea73ad482de3c552debe *R/describe.s
3131 6cb5b3a77860b605f102bb528e84a071 *R/discrete.s
3232 a96e8a7c59626e7cb975f79eb869b025 *R/dotchart3.s
3333 01ac1a5622f257498eefc940f11c8615 *R/ecdf.s
5151 8cf9e0a10997c59a5be3f19a39c73684 *R/james.stein.s
5252 88c72d01c0b5a4f5d40f919918bfbd00 *R/labcurve.s
5353 df6cc0711c0f32bd8524560fc403dbff *R/label.s
54 8fc31a2fcfe7d0aa1abc9dd2e5188eae *R/latex.s
54 f20844d838120469e5167a1933e90071 *R/latex.s
5555 15f9f1d9ce01c4624523182f7a514244 *R/latexDotchart.s
5656 9fafa76ce37fa2f42c27236c9bbcfb9d *R/latexTabular.s
5757 330de4a4106a11330d54434e2d7a8c32 *R/latexTherm.s
6161 e21c3cbb9b9c17b07223d4f805433395 *R/makeNstr.s
6262 e5f0eef89d954522d56fb5399066a6d3 *R/mask.s
6363 f4cc097babcda3c1edcd60f516713ff2 *R/matxv.s
64 f0d3e83235352d62cc0714846821c68e *R/mdb.get.s
64 c43b31317d74ac389aff80c7adf7efa5 *R/mdb.get.s
6565 1c430f0b7f3caed1b15359483136509d *R/minor.tick.s
6666 32a369e847b95005134970ac15b4ba73 *R/model.frame.default.s
6767 fc71dbaeeb57983dcfa3ac0497ed837b *R/mtitle.s
7676 215f9a06ffc6df02fb67576ad0da83b9 *R/panel.abwplot.s
7777 35e90e268046316b9369585f790bdd9a *R/panel.bpplot.s
7878 1630c1be85251dac0e8cd0243bedd201 *R/pc1.s
79 187f93b46f9d3d54258618f1cb7a1333 *R/plsmo.s
79 b4c352cd36449e5ec442b9badb45c9d2 *R/plsmo.s
8080 ce22555a4a09e120b39f9eec3320b37c *R/popower.s
8181 9a1119c7949407c39968645e921a87a6 *R/print.char.list.s
8282 afe3fb9a3b0fa665e0811fd2b1ace401 *R/pstamp.s
109109 b42e6d7953adef86625842fa4bdbe291 *R/strwrap.s
110110 055ef617ac4b0362b6466e6436ba69fb *R/subplot.s
111111 14e533b635192fae8b28ca81b9c86f5d *R/substi.s
112 fb4587629a1bb412968b1c55092900c3 *R/summary.formula.s
113 e820a611b7ad0ef9fa7c8a4751a74839 *R/summaryM.s
112 abcd76fbff84661c057ae17869fecc40 *R/summary.formula.s
113 da2e1714f9e6874e265dedf924bb2fb5 *R/summaryM.s
114114 7968792139f8f165a2725d04be6d7600 *R/summaryP.s
115115 dc27150ba262b8c3844ce46d36f1e492 *R/summaryRc.s
116116 598051fb147f0879ecb04ad4a0dfe54f *R/summaryS.s
125125 91c82b7b8e9ad8cff084bf7b2069d11b *R/units.s
126126 25b2e4d51ba3475a3e2bd22da07305ad *R/valueTags.s
127127 ce9c8d4ed31e5172583f329e103dcbe4 *R/varclus.s
128 02c2c59f781d8c3433c0b4ffae2f54d4 *R/wtd.stats.s
128 6fb48df83188e5a99022fdcfb106cb0e *R/wtd.stats.s
129129 fafd82249f6870351f42d4ad6c3757c5 *R/xYplot.s
130130 ceb40edad1b482275efde229ce48cdea *R/xtfrm.labelled.s
131131 b72b2ab287d4c1af9d741022300a18bb *R/xy.group.s
142142 d04e0431bff384660d258b2e2e405b32 *man/Hmisc-internal.Rd
143143 a8d3213ffdeb74c3f50bb2d54a8b9ab5 *man/Lag.Rd
144144 1dcfad836f562a867431ea9225ef009d *man/Misc.Rd
145 81e0509297dea67156903a55e89339b4 *man/Overview.Rd
145 0beff88dfa85ab0fd7b4306272170a8f *man/Overview.Rd
146146 0b14624c4cf49f60e6447e2792b227c6 *man/Save.Rd
147147 6512b9f5df15df6558a987169ebbc216 *man/abs.error.pred.Rd
148148 ccb2959a926f28700383197d9496151d *man/addMarginal.Rd
160160 d787d413eeb83e8f9cd809d4630a9f99 *man/ciapower.Rd
161161 4202bd798ad52004eec93d91b0a8d945 *man/cnvrt.coords.Rd
162162 00db76a86189178fe8385d5aaeda346b *man/consolidate.Rd
163 214346eb5560c930d14d2318c26959d9 *man/contents.Rd
163 e94ba9a8822c12a12ed1fa3c5f3526f2 *man/contents.Rd
164164 11c78317d89330da550b16617b3b96a6 *man/cpower.Rd
165165 5673d004d5398e681cc11521217a38ca *man/csv.get.Rd
166 588c98170b6ff457695cfe40cc409f78 *man/curveRep.Rd
166 3189e5ba69e3ed68dfbe16b8272837eb *man/curveRep.Rd
167167 8837df3d98894a30648d941bed708600 *man/cut2.Rd
168168 3f0207be8386db756a98655b26cc21be *man/data.frame.create.modify.check.Rd
169169 2ead582aeae9e126400a6b4ad683e264 *man/dataRep.Rd
195195 216bb0989ebf4378cb87841082451438 *man/inc-dec.Rd
196196 40974ee6be081e636f57e6649b6fde38 *man/labcurve.Rd
197197 c9a14ef836c70a6c1ba034f40505006b *man/label.Rd
198 c7bdf4b6b293f2382bd9cb95884e5f4c *man/latex.Rd
198 acb1fe98c820d282892d7a63cb1ee43c *man/latex.Rd
199199 211c0afb26e58d9aee079d5ee9bebc95 *man/latexDotchart.Rd
200200 27998cfcd912e12c8ca2a0ae72a0f3fb *man/latexTabular.Rd
201201 0bc6e69386de30a3e231170b3d19a218 *man/latexTherm.Rd
204204 7a3ad23a76192d3d91b2995a098bfabb *man/mApply.Rd
205205 6aaa5648e29fa7bbbffcc6abb94a003e *man/mChoice.Rd
206206 c2c3d7fd7b6118a5480308fcacb57afa *man/makeNstr.Rd
207 15299005b391107453578c49e8b3f75a *man/mdb.get.Rd
207 7b897bfa6c2c3500b188ef4db8b3c112 *man/mdb.get.Rd
208208 02d1f868b81a79ca95f29a1237ffea4e *man/mgp.axis.Rd
209209 3808e059fc503259824eb5cc2bc0b621 *man/minor.tick.Rd
210210 d513cb5e98a79934c27f37e090d9c849 *man/mtitle.Rd
258258 9a4cac30cfc22acf2afa062a30b62d9c *man/stringDims.Rd
259259 bbd0b4524bd9a4e350d6a7ad4aca3a0a *man/subplot.Rd
260260 5f57bda18966651336d67c9815a4a735 *man/summarize.Rd
261 0944ea9a5cd83e6c55f5101b72b16510 *man/summary.formula.Rd
262 c993d780a236a0b93067be0df044df6e *man/summaryM.Rd
261 f01235c13973dda377b308305ef2c522 *man/summary.formula.Rd
262 5280d7d8d537e0bde0b0628e742b337c *man/summaryM.Rd
263263 83d5ba5f470f16b143e9dc9505789054 *man/summaryP.Rd
264264 7ca4294ccd0452d806afe92197d4b6c5 *man/summaryRc.Rd
265265 e82661d26ccd2ab7689b3cb63113c65d *man/summaryS.Rd
278278 05327becfe12abbbc92e8f5c342197a5 *man/valueTags.Rd
279279 5b38e2511ce2b1f47cbb217211b5a803 *man/varclus.Rd
280280 bc5f53ee64bd18f64dd31271902608ca *man/windows/sas.get.Rd
281 3829ebdffaf2cff78fb395416b9dbb5f *man/wtd.stats.Rd
281 bb8aba91aba23e8359f046a3cf7854ad *man/wtd.stats.Rd
282282 7bcbae4f32d3a80d4bcd721f45aa9ede *man/xYplot.Rd
283283 13c3f8a542f16076e346f9d6cc7904c3 *man/xtfrm.labelled.Rd
284284 83b8f2732a6c378785187242ff93b26a *man/xy.group.Rd
324324 bc723e6e82c91373f2c3f142bbe0be59 *tests/inverseFunction.r
325325 573465e16901912adb87c138b62056c6 *tests/largest.empty.r
326326 a1e0437dadc110e13e67c1f72235bfb5 *tests/latex.s
327 665a97c81e3fafa665ec1365a9997242 *tests/latex.summaryM.Rnw
327 969b3b3132b54e2b4a174e8c251338b0 *tests/latex.summaryM.Rnw
328328 86bb29e3df2c4cc1dab74549971ca150 *tests/latexTherm.Rnw
329329 2a119079fd599b3fd6f64b6f579de087 *tests/latexTherm.r
330330 c0668a4323dcc6d83736668c00456d23 *tests/minor.tick.r
2222 S3method(plot, summaryS)
2323 S3method(label, default)
2424 S3method(label, data.frame)
25 S3method('label<-', default)
26 S3method('label<-', data.frame)
27 S3method('[', labelled)
28 S3method(print, labelled)
2529 S3method(label, Surv)
2630 S3method(units, default)
2731 S3method(units, Surv)
0 Changes in version 3.14-6 (2014-11-16)
1 * wtd.rank: fixed bug in no weights case (thanks: DPlat)
2 * latex.summaryM, latex.summary.formula.reverse: added npct='slash' to present numerators and denominators horizontally instead of vertically
3 * plsmo: put derivation of ylab earlier so will use original attributes
4 * NAMESPACE: exported more S3 methods for label
5 * contents: added arguments id, range, values
6 * print.contents.data.frame, html.contents.data.frame: added maxlevels argument
7 * curveRep: added option to have the color of frequencies displayed match line colors. Thanks: jstat10
8 * curveRep: changed call to strwidth to use units instead of unit argument
9 * contents.data.frame: corrected omission in help file
10 * wtd.var: corrected denominator. Thanks: Shan Huang
11 * latex.default: changed to use colheads=FALSE to suppress column headings. Thanks: Michael Rose
12 * mdb.get: added system option -b strip to mdb-export to skip binary output
13
014 Changes in version 3.14-5 (2014-09-11)
115 * latex.summaryM: fixed bug in caption with test=TRUE. Thanks: Yonghao Pua
216 * csv.get: uses data.table package's fread in place of read.csv if data.table is in effect
0 ## $Id$
10 curveRep <- function(x, y, id, kn=5, kxdist=5, k=5, p=5, force1=TRUE,
21 metric=c('euclidean','manhattan'),
32 smooth=FALSE, extrap=FALSE, pr=FALSE) {
143142 nx=NULL, fill=TRUE,
144143 idcol=NULL, freq=NULL, plotfreq=FALSE,
145144 xlim=range(x), ylim=range(y),
146 xlab='x', ylab='y', ...) {
145 xlab='x', ylab='y', colorfreq=FALSE, ...) {
147146 method <- match.arg(method)
148147 ncuts <- x$ncuts
149148 res <- x$res; id <- x$id; y <- x$y; k <- x$k; x <- x$x
235234 return()
236235 }
237236 txt <- paste(names(tab), tab, sep=':')
237 txt2 <- txt
238238 paste(txt, collapse=';')
239239 } else {
240240 size <- sizecluster[subscripts[1]]
241241 paste('N=',size,sep='')
242242 }
243 grid.text(txt, x=.005, y=.99, just=c(0,1),
244 gp=gpar(fontsize=9, col=gray(.25)))
243 if (!colorfreq | is.null(idcol) | is.null(freq)) #Do same as original
244 {
245 grid.text(txt, x = 0.005, y = 0.99, just = c(0, 1),
246 gp = gpar(fontsize = 9, col = gray(0.25)))
247 }
248 else #color freq text using idcol
249 {
250 mycolors<-data.frame(idcol,freq)
251 mycolors<-unique(mycolors)
252 curtext<-txt2[1]
253 curtrt<-strsplit(curtext,':')[[1]][1]
254 curcol<-as.character( mycolors[ curtrt==as.character( mycolors[,2]) ,1] )
255
256 grid.text(curtext,
257 x = 0.005,
258 y = 0.99,
259 just = c(0, 1),
260 gp = gpar(fontsize = 9, col =curcol)
261 )
262 emspace<-2*strwidth('M', units="figure")
263 for (i in 2:length(txt2))
264 {
265 curtext<-txt2[i]
266 curtrt<-strsplit(curtext,':')[[1]][1]
267 curcol<-as.character( mycolors[ curtrt==as.character( mycolors[,2]) ,1] )
268
269 grid.text(curtext,
270 x = emspace+strwidth(txt2[i-1], units="figure") ,
271 y = 0.99, just = c(0, 1),
272 gp = gpar(fontsize = 9, col = curcol)
273 )
274 }
275 }
245276 }
246277 pan <- if(length(idcol))
247278 function(x, y, subscripts, groups, type, ...) {
685685
686686 contents <- function(object, ...) UseMethod('contents')
687687
688 contents.data.frame <- function(object, sortlevels=FALSE, ...)
688 contents.data.frame <- function(object, sortlevels=FALSE,
689 id=NULL, range=NULL, values=NULL, ...)
689690 {
690691 dfname <- deparse(substitute(object))
691692 nam <- names(object)
697698 for(i in 1:n) {
698699 x <- object[[i]]
699700 at <- attributes(x)
700 if(length(at$label))
701 lab[i] <- at$label
702 if(length(at$longlabel))
703 longlab[i] <- at$longlabel
704
705 if(length(at$units))
706 un[i] <- at$units
701 if(length(at$label)) lab[i] <- at$label
702 if(length(at$longlabel)) longlab[i] <- at$longlabel
703
704 if(length(at$units)) un[i] <- at$units
707705
708706 atl <- at$levels
709707 fl[i] <- length(atl)
710 cli <- at$class[at$class %nin% c('labelled','factor')]
711 if(length(cli))
712 cl[i] <- cli[1]
708 cli <- at$class[at$class %nin% c('labelled', 'factor')]
709 if(length(cli)) cl[i] <- cli[1]
713710
714711 sm[i] <- storage.mode(x)
715712 nas[i] <- sum(is.na(x))
716713 if(length(atl)) {
717714 if(sortlevels) atl <- sort(atl)
718 if(length(Lev)) for(j in 1:length(Lev)) {
715 if(length(Lev)) for(j in 1 : length(Lev)) {
719716 w <- Lev[[j]]
720717 if(!is.name(w) && is.logical(all.equal(w, atl))) {
721718 atl <- as.name(names(Lev)[j])
726723 }
727724 }
728725
729 w <- list(Labels=if(any(lab!='')) lab,
730 Units=if(any(un!='')) un,
731 Levels=if(any(fl>0)) fl,
732 Class=if(any(cl!='')) cl,
733 Storage= sm,
734 NAs=if(any(nas>0)) nas )
735
736 w <- w[sapply(w, function(x)length(x)>0)]
726 w <- list(Labels = if(any(lab != '')) lab,
727 Units = if(any(un != '')) un,
728 Levels = if(any(fl > 0)) fl,
729 Class = if(any(cl != '')) cl,
730 Storage= sm,
731 NAs = if(any(nas > 0)) nas )
732
733 w <- w[sapply(w, function(x)length(x) > 0)]
737734
738735 ## R does not remove NULL elements from a list
739736 structure(list(contents=data.frame(w, row.names=nam),
740 dim=d, maxnas=max(nas), dfname=dfname,
737 dim=d, maxnas=max(nas),
738 id=id, rangevar=range, valuesvar=values,
739 unique.ids = if(length(id) && id %in% nam)
740 length(unique(object[[id]])),
741 range = if(length(range) && range %in% nam)
742 paste(as.character(range(object[[range]], na.rm=TRUE)),
743 collapse='-'),
744 values = if(length(values) && values %in% nam)
745 paste(if(is.factor(object[[values]])) levels(object[[values]])
746 else sort(unique(object[[values]])), collapse=' '),
747 dfname=dfname,
741748 Levels=Lev,
742 longLabels=if(any(longlab!='')) structure(longlab, names=nam)),
749 longLabels=if(any(longlab!=''))
750 structure(longlab, names=nam)),
743751 class='contents.data.frame')
744752 }
745753
746754
747755 print.contents.data.frame <-
748756 function(x, sort=c('none','names','labels','NAs'),
749 prlevels=TRUE, number=FALSE, ...)
757 prlevels=TRUE, maxlevels=Inf, number=FALSE, ...)
750758 {
751759 sort <- match.arg(sort)
752760 d <- x$dim
753761 maxnas <- x$maxnas
754 cat('\nData frame:',x$dfname,'\t',d[1],' observations and ',d[2],
755 ' variables Maximum # NAs:',maxnas,'\n\n',sep='')
762 cat('\nData frame:', x$dfname, '\t', d[1],' observations and ', d[2],
763 ' variables Maximum # NAs:', maxnas, '\n', sep='')
764 if(length(x$id)) cat('Unique ', x$id, ':', x$unique.ids, '\t', sep='')
765 if(length(x$rangevar)) cat(x$rangevar, ' range:', x$range, '\t', sep='')
766 if(length(x$valuesvar))cat(x$valuesvar, ':', x$values, sep='')
767 cat('\n\n')
756768 cont <- x$contents
757769 nam <- row.names(cont)
758770 if(number) row.names(cont) <- paste(format(1:d[2]), row.names(cont))
763775 },
764776 labels={
765777 if(length(cont$Labels))
766 cont <- cont[order(cont$Labels, nam),,drop=FALSE]
778 cont <- cont[order(cont$Labels, nam),, drop=FALSE]
767779 },
768780 NAs={
769 if(maxnas>0)
770 cont <- cont[order(cont$NAs,nam),,drop=FALSE]
781 if(maxnas > 0)
782 cont <- cont[order(cont$NAs, nam),, drop=FALSE]
771783 })
772784
773785 if(length(cont$Levels))
774 cont$Levels <- ifelse(cont$Levels==0,'',format(cont$Levels))
786 cont$Levels <- ifelse(cont$Levels == 0, '', format(cont$Levels))
775787
776788 print(cont)
777789
778790 if(prlevels && length(L <- x$Levels)) {
779791 cat('\n')
780792 nam <- names(L)
781 w <- .Options$width-max(nchar(nam))-5
793 w <- .Options$width - max(nchar(nam)) - 5
782794 reusingLevels <- sapply(L, is.name)
783 fullLevels <- which(!reusingLevels)
795 fullLevels <- which(!reusingLevels)
784796 namf <- lin <- names(L[fullLevels])
785797 ## separate multiple lines per var with \n for print.char.matrix
786798 j <- 0
787 for(i in fullLevels)
788 {
789 j <- j + 1
790 varsUsingSame <- NULL
791 if(sum(reusingLevels))
792 {
793 for(k in which(reusingLevels)) if(L[[k]] == namf[j])
794 varsUsingSame <- c(varsUsingSame, nam[k])
795 if(length(varsUsingSame))
796 namf[j] <- paste(c(namf[j], varsUsingSame), collapse='\n')
797 }
798 lin[j] <- paste(pasteFit(L[[i]], width=w), collapse='\n')
799 for(i in fullLevels) {
800 j <- j + 1
801 varsUsingSame <- NULL
802 if(sum(reusingLevels)) {
803 for(k in which(reusingLevels))
804 if(L[[k]] == namf[j]) varsUsingSame <- c(varsUsingSame, nam[k])
805 if(length(varsUsingSame))
806 namf[j] <- paste(c(namf[j], varsUsingSame), collapse='\n')
799807 }
808 Li <- L[[i]]
809 if(length(Li) > maxlevels) Li <- c(Li[1 : maxlevels], '...')
810 lin[j] <- paste(pasteFit(Li, width=w), collapse='\n')
811 }
800812 z <- cbind(Variable=namf, Levels=lin)
801813 print.char.matrix(z, col.txt.align='left', col.name.align='left',
802814 row.names=TRUE, col.names=TRUE)
822834
823835
824836 html.contents.data.frame <-
825 function(object, sort=c('none','names','labels','NAs'), prlevels=TRUE,
826 file=paste('contents',object$dfname,'html',sep='.'),
827 levelType=c('list','table'),
837 function(object, sort=c('none', 'names', 'labels', 'NAs'), prlevels=TRUE,
838 maxlevels=Inf, file=paste('contents',object$dfname, 'html', sep='.'),
839 levelType=c('list', 'table'),
828840 append=FALSE, number=FALSE, nshow=TRUE, ...)
829841 {
830842 sort <- match.arg(sort)
831843 levelType <- match.arg(levelType)
832844 d <- object$dim
833845 maxnas <- object$maxnas
834 if(nshow)
846 if(nshow) {
835847 cat('<hr><h2>Data frame:',object$dfname,
836848 '</h2>',d[1],
837849 ' observations and ',d[2],
838 ' variables, maximum # NAs:',maxnas,'<hr>\n',sep='',
839 file=file, append=append)
840 else
850 ' variables, maximum # NAs:',maxnas, '&nbsp&nbsp&nbsp&nbsp',
851 sep='', file=file, append=append)
852 if(length(object$id)) cat('Unique ', object$id, ':', object$unique.ids,
853 '&nbsp&nbsp&nbsp&nbsp',
854 sep='', file=file, append=TRUE)
855 if(length(object$rangevar)) cat(object$rangevar, ' range:', object$range,
856 '&nbsp&nbsp&nbsp&nbsp', sep='', file=file, append=TRUE)
857 if(length(object$valuesvar))cat(object$valuesvar, ':', object$values,
858 '&nbsp&nbsp&nbsp&nbsp', sep='', file=file, append=TRUE)
859 cat('<hr>\n', file=file, append=TRUE)
860 } else
841861 cat('<hr><h2>Data frame:',object$dfname,
842862 '</h2>', ' Variables:', d[2], '<hr>\n', sep='',
843863 file=file, append=append)
893913
894914 cat('<hr>\n', file=file, append=TRUE)
895915
896 if(prlevels && length(L)) {
916 if(prlevels && length(L) > 0) {
897917 if(levelType=='list') {
898918 cat('<h2 align="center">Category Levels</h2>\n', file=file, append=TRUE)
899919 for(i in fullLevels) {
907927 paste(w, collapse=', '), '</h3>\n', sep='',
908928 file=file, append=TRUE)
909929 cat('<ul>\n', file=file, append=TRUE)
930 if(length(l) > maxlevels) l <- c(l[1 : maxlevels], '...')
910931 for(k in l) cat('<li>', k, '</li>\n', sep='',
911932 file=file, append=TRUE)
912933 cat('</ul>\n', file=file, append=TRUE)
917938 ## possible into n elements, pasting multiple elements
918939 ## together when needed
919940 evenSplit <- function(x, n) {
920 indent <- function(z) if(length(z)==1)z else
921 c(z[1], paste('&nbsp&nbsp&nbsp',z[-1],sep=''))
941 indent <- function(z) if(length(z) == 1) z else
942 c(z[1], paste('&nbsp&nbsp&nbsp', z[-1], sep=''))
922943 m <- length(x)
923944 if(m <= n) return(c(indent(x), rep('',n-m)))
924945 totalLength <- sum(nchar(x)) + (m-1)*3.5
933954 if(m <= n) break
934955 }
935956 ## Take evasive action if needed
936 if(m==n) indent(y) else if(m < n)
937 c(indent(y), rep('', n-m)) else
938 c(paste(x, collapse=', '), rep('',n-1))
957 if(m == n) indent(y) else if(m < n)
958 c(indent(y), rep('', n - m)) else
959 c(paste(x, collapse=', '), rep('', n - 1))
939960 }
940961 nam <- names(L)
941962 v <- lab <- lev <- character(0)
943964 for(i in fullLevels) {
944965 j <- j + 1
945966 l <- L[[i]]
967 if(length(l) > maxlevels) l <- c(l[1 : maxlevels], '...')
946968 nami <- nam[i]
947969 v <- c(v, nami)
948970 w <- nami
381381 double.slash=double.slash, ...)
382382 if (missing(rowname))
383383 rowname <- dimnames(cx)[[1]]
384
385 nocolheads <- length(colheads) == 1 && is.logical(colheads) && ! colheads
384386
385387 if (!length(colheads))
386388 colheads <- dimnames(cx)[[2]]
742744 labs <- colheads
743745 if (length(colnamesTexCmd))
744746 labs <- paste(sl, colnamesTexCmd, " ", labs, sep="")
747 if(nocolheads) colheads <- labs <- NULL
745748 header <- NULL
746749 if(length(labs)) {
747750 if(!length(extracolheads)) {
754757 if(multicol)
755758 colheads <- paste(slmc1, cvbar, "}{", colheads, "}", sep="")
756759
757 header <- paste(colheads, collapse='&')
760 header <- if(length(colheads)) paste(colheads, collapse='&')
758761 if(length(extracolheads)) {
759762 extracolheads <- ifelse(extracolheads == ''| extracolsize == '',
760763 extracolheads,
768771 extracolheads <- ifelse(extracolheads == '',extracolheads,
769772 paste(extracolheads,sep=''))
770773
771 header <- paste(header, eol, paste(extracolheads, collapse='&'), sep='')
774 header <- if(length(header))
775 paste(header, eol, paste(extracolheads, collapse='&'), sep='')
772776 }
773777
774 cat(header, eog, file=file, sep='', append=file!='')
778 if(length(header)) cat(header, eog, file=file, sep='', append=file!='')
775779
776780 if(ctable)
777781 cat(midrule, file=file, append=file!='')
791795 cat(midrule, sep="",file=file, append=file!='')
792796 if(length(cgroupheader))
793797 cat(cgroupheader, file=file, append=file!='')
794 cat(header, file=file, sep="&", append=file!='')
798 if(length(header)) cat(header, file=file, sep="&", append=file!='')
795799 cat(eog, midrule, sl, "endhead", '\n', midrule,
796800 sep="", file=file, append=file!='')
797801 if(length(insert.bottom)) {
2222 if(lowernames) vnames <- casefold(vnames)
2323 types <- sapply(s, function(x)x[length(x)])
2424 datetime <- vnames[grep('DateTime', s)]
25 system(paste('mdb-export', file, shQuote(tab), '>', f))
25 system(paste('mdb-export -b strip', file, shQuote(tab), '>', f))
2626 d <- csv.get(f, datetimevars=datetime,
2727 lowernames=lowernames, allow=allow,
2828 dateformat=dateformat, ...)
99 gfun <- ordGridFun(grid)
1010 nam <- as.character(sys.call())[2 : 3]
1111 method <- match.arg(method)
12 if(missing(ylab))
13 ylab <- label(y, units=TRUE, plot=TRUE, default=nam[2])
1214 Y <- as.matrix(y)
1315 p <- ncol(Y)
1416 if(!missing(subset)) {
8385 else {
8486 if(missing(xlab))
8587 xlab <- label(x, units=TRUE, plot=TRUE, default=nam[1])
86 if(missing(ylab))
87 ylab <- label(Y, units=TRUE, plot=TRUE, default=nam[2])
88
88
8989 if(missing(xlim)) xlim <- c(xmin, xmax)
9090 if(missing(ylim)) ylim <- c(ymin, ymax)
9191 plot(xmin, ymin, xlim=xlim, ylim=ylim,
14691469 switch(npct,
14701470 numerator=paste('{\\',npct.size,' (',format(tab),')}',sep=''),
14711471 denominator=paste('{\\',npct.size,' of',denom.rep,'}'),
1472 both=paste('{\\',npct.size,' $\\frac{',
1473 format(tab),'}{',denom.rep,
1474 '}$}',sep=''))
1472 both=paste('{\\', npct.size, ' $\\frac{', format(tab),'}{',
1473 denom.rep,'}$}',sep=''),
1474 slash=paste('~{\\', npct.size, ' ', format(tab),
1475 '\\,/\\,', # \, = LaTeX thin space
1476 denom.rep, '}', sep='')
1477 )
14751478 else
14761479 switch(npct,
14771480 numerator=paste('(',format(tab),')',sep=''),
17541757 function(object, title=first.word(deparse(substitute(object))),
17551758 digits, prn = any(n!=N), pctdig=0,
17561759 what=c('%', 'proportion'),
1757 npct=c('numerator','both','denominator','none'),
1760 npct=c('numerator','both','denominator','slash','none'),
17581761 npct.size='scriptsize', Nsize='scriptsize',
17591762 exclude1=TRUE, vnames=c("labels","names"), prUnits=TRUE,
17601763 middle.bold=FALSE, outer.size="scriptsize",
557557 file=paste(title, 'tex', sep='.'), append=FALSE,
558558 digits, prn = any(n!=N),
559559 what=c('proportion', '%'), pctdig=if(what=='%') 0 else 2,
560 npct=c('numerator','both','denominator','none'),
560 npct=c('numerator','both','denominator','slash','none'),
561561 npct.size='scriptsize', Nsize='scriptsize',
562562 exclude1=TRUE, vnames=c("labels","names"), prUnits=TRUE,
563563 middle.bold=FALSE, outer.size="scriptsize",
2424 }
2525
2626 if(normwt)
27 weights <- weights*length(x)/sum(weights)
28
29 xbar <- sum(weights*x)/sum(weights)
30 sum(weights*((x - xbar)^2)) / (sum(weights) - 1)
27 weights <- weights * length(x) / sum(weights)
28
29 sw <- sum(weights)
30 xbar <- sum(weights * x) / sw
31 sum(weights*((x - xbar)^2)) / (sw - sum(weights ^ 2) / sw)
3132 }
3233
3334
182183 wtd.rank <- function(x, weights=NULL, normwt=FALSE, na.rm=TRUE)
183184 {
184185 if(!length(weights))
185 return(rank(x),na.last=if(na.rm)NA else TRUE)
186 return(rank(x, na.last=if(na.rm) NA else TRUE))
186187
187188 tab <- wtd.table(x, weights, normwt=normwt, na.rm=na.rm)
188189
4646 bsamsize \tab Sample size requirements for test of 2 proportions\cr
4747 bystats \tab Statistics on a single variable by levels of >=1 factors\cr
4848 bystats2 \tab 2-way statistics\cr
49 calltree \tab Calling tree of functions \cr
50 \tab (David Lubinsky, \email{david@hoqax.att.com})\cr
5149 character.table \tab Shows numeric equivalents of all latin characters\cr
5250 \tab Useful for putting many special chars. in graph titles\cr
5351 \tab (Pierre Joyet, \email{pierre.joyet@bluewin.ch})\cr
2929 }
3030 \usage{
3131 contents(object, \dots)
32 \method{contents}{data.frame}(object, sortlevels=FALSE, \dots)
32 \method{contents}{data.frame}(object, sortlevels=FALSE, id=NULL,
33 range=NULL, values=NULL, \dots)
3334 \method{print}{contents.data.frame}(x,
34 sort=c('none','names','labels','NAs'), prlevels=TRUE, number=FALSE, \dots)
35 sort=c('none','names','labels','NAs'), prlevels=TRUE, maxlevels=Inf,
36 number=FALSE, \dots)
3537 \method{html}{contents.data.frame}(object,
36 sort=c('none','names','labels','NAs'), prlevels=TRUE,
38 sort=c('none','names','labels','NAs'), prlevels=TRUE, maxlevels=Inf,
3739 file=paste('contents',object$dfname,'html',sep='.'),
3840 levelType=c('list','table'),
3941 append=FALSE, number=FALSE, nshow=TRUE, \dots)
5153 variables use the same levels but in different orders. They will
5254 still be recognized by the \code{html} method as having identical
5355 levels if sorted.}
56 \item{id}{an optional subject ID variable name that if present in
57 \code{object} will cause the number of unique IDs to be printed in
58 the contents header}
59 \item{range}{an optional variable name that if present in \code{object}
60 will cause its range to be printed in the contents header}
61 \item{values}{an optional variable name that if present in
62 \code{object} will cause its unique values to be printed in the
63 contents header}
5464 \item{x}{
5565 an object created by \code{contents}
5666 }
6676 \item{prlevels}{
6777 set to \code{FALSE} to not print all levels of \code{factor} variables
6878 }
79 \item{maxlevels}{maximum number of levels to print for a \code{factor} variable}
6980 \item{number}{
7081 set to \code{TRUE} to have the \code{print} and \code{latex} methods
7182 number the variables by their order in the data frame
6262 m=NULL, probs=c(.5, .25, .75), nx=NULL, fill=TRUE,
6363 idcol=NULL, freq=NULL, plotfreq=FALSE,
6464 xlim=range(x), ylim=range(y),
65 xlab='x', ylab='y', \dots)
65 xlab='x', ylab='y', colorfreq=FALSE, \dots)
6666 curveSmooth(x, y, id, p=NULL, pr=TRUE)
6767
6868 }
133133 Applies only to \code{method = "lattice"}. By default the largest bar
134134 is 0.1 times the length of a panel's x-axis. Specify
135135 \code{plotfreq = 0.5} for example to make the longest bar half this long.}
136 \item{colorfreq}{set to \code{TRUE} to color the frequencies printed by
137 \code{plotfreq} using the colors provided by \code{idcol}.}
136138 \item{xlim, ylim, xlab, ylab}{plotting parameters. Default ranges are
137139 the ranges in the entire set of raw data given to \code{curveRep}.}
138140 \item{\dots}{arguments passed to other functions.}
313313 justification for labels for column groups. Defaults to \code{"c"}.
314314 }
315315 \item{colheads}{a character vector of column headings if you don't want
316 to use \code{dimnames(object)[[2]]}. Specify \code{colheads=NULL} to
316 to use \code{dimnames(object)[[2]]}. Specify \code{colheads=FALSE} to
317317 suppress column headings.}
318318 \item{extracolheads}{
319319 an optional vector of extra column headings that will appear under the
3131 }
3232 \details{
3333 Uses the \code{mdbtools} package executables \code{mdb-tables},
34 \code{mdb-schema}, and \code{mdb-export}. In Debian/Ubuntu Linux run
34 \code{mdb-schema}, and \code{mdb-export} (with option \code{-b strip}
35 to drop any binary output). In Debian/Ubuntu Linux run
3536 \code{apt get install mdbtools}.
3637 \code{cleanup.import} is invoked by \code{csv.get} to transform
3738 variables and store them as efficiently as possible.
130130
131131 \method{latex}{summary.formula.reverse}(object, title = first.word(deparse(substitute(object))), digits,
132132 prn = any(n != N), pctdig = 0, what=c('\%', 'proportion'),
133 npct = c("numerator", "both", "denominator", "none"),
133 npct = c("numerator", "both", "denominator", "slash", "none"),
134134 npct.size = 'scriptsize', Nsize = "scriptsize", exclude1 = TRUE,
135135 vnames=c("labels", "names"), prUnits = TRUE, middle.bold = FALSE,
136136 outer.size = "scriptsize", caption, rowlabel = "",
416416 specifies which counts are to be printed to the right of percentages.
417417 The default is to print the frequency (numerator of the percent) in
418418 parentheses. You can specify \code{"both"} to print both numerator and
419 denominator, \code{"denominator"}, or \code{"none"}.
419 denominator, \code{"denominator"}, \code{"slash"} to
420 typeset horizontally using a forward slash, or \code{"none"}.
420421 }
421422 \item{npct.size}{
422423 the size for typesetting \code{npct} information which appears after percents.
7878 file=paste(title, 'tex', sep='.'), append=FALSE, digits,
7979 prn = any(n != N), what=c('proportion', '\%'),
8080 pctdig = if(what == '\%') 0 else 2,
81 npct = c('numerator', 'both', 'denominator', 'none'),
81 npct = c('numerator', 'both', 'denominator', 'slash', 'none'),
8282 npct.size = 'scriptsize', Nsize = 'scriptsize', exclude1 = TRUE,
8383 vnames=c("labels", "names"), prUnits = TRUE, middle.bold = FALSE,
8484 outer.size = "scriptsize", caption, rowlabel = "",
237237 specifies which counts are to be printed to the right of percentages.
238238 The default is to print the frequency (numerator of the percent) in
239239 parentheses. You can specify \code{"both"} to print both numerator and
240 denominator, \code{"denominator"}, or \code{"none"}.
240 denominator as a fraction, \code{"denominator"}, \code{"slash"} to
241 typeset horizontally using a forward slash, or \code{"none"}.
241242 }
242243 \item{npct.size}{
243244 the size for typesetting \code{npct} information which appears after
162162 Gatz DF, Smith L (1995): The standard error of a weighted mean
163163 concentration--II. Estimating confidence intervals. Atmospheric Env
164164 29:1195-1200.
165
166 http://en.wikipedia.org/wiki/Weighted_arithmetic_mean
165167 }
166168 \seealso{
167169 \code{\link{mean}}, \code{\link{var}}, \code{\link{quantile}}, \code{\link{table}}, \code{\link{rank}}, \code{\link{loess.smooth}}, \code{\link{lowess}},
4646 <<echo=FALSE, results='asis'>>=
4747 latex(summaryM(age + height + type ~ sex , data=dbase, overall=TRUE, test=TRUE),
4848 size='small', where="ht",
49 long=TRUE, prmsd = TRUE,
49 long=TRUE, prmsd = TRUE, npct='slash',
5050 caption="Descriptive Statistics",
5151 msdsize='scriptsize', round = 2, digits=2, prtest='P', pdig =2, file='',
5252 label="table:summary")
6464 caption="Descriptive stats and tests of between-group differences for all primary and secondary neuroimaging outcomes",
6565 label= "tbl:descrOutcomes",
6666 exclude1=FALSE, digits=2, long=TRUE, prmsd=TRUE,
67 npct="both", size="tiny",
67 npct="slash", size="tiny", npct.size='tiny',
6868 center="centering")
6969 @
70
71 Put a complex table in an external \texttt{.tex} file for conversion
72 to \texttt{html} using \texttt{htlatex}:
73 <<extex>>=
74 ## Example taken from help file for summaryM
75 options(digits=3)
76 set.seed(173)
77 sex <- factor(sample(c("m","f"), 500, rep=TRUE))
78 country <- factor(sample(c('US', 'Canada'), 500, rep=TRUE))
79 age <- rnorm(500, 50, 5)
80 sbp <- rnorm(500, 120, 12)
81 label(sbp) <- 'Systolic BP'
82 units(sbp) <- 'mmHg'
83 treatment <- factor(sample(c("Drug","Placebo"), 500, rep=TRUE))
84 treatment[1]
85 sbp[1] <- NA
86
87 # Generate a 3-choice variable; each of 3 variables has 5 possible levels
88 symp <- c('Headache','Stomach Ache','Hangnail',
89 'Muscle Ache','Depressed')
90 symptom1 <- sample(symp, 500,TRUE)
91 symptom2 <- sample(symp, 500,TRUE)
92 symptom3 <- sample(symp, 500,TRUE)
93 Symptoms <- mChoice(symptom1, symptom2, symptom3, label='Primary Symptoms')
94 table(as.character(Symptoms))
95 # Produce separate tables by country
96 f <- summaryM(age + sex + sbp + Symptoms ~ treatment + country,
97 groups='treatment', test=TRUE)
98 fi <- '/tmp/z.tex'
99 cat('\\documentclass{report}\\begin{document}\n', file=fi)
100 w <- latex(f, file=fi, npct='slash', middle.bold=TRUE, prmsd=TRUE, append=TRUE)
101 cat('\\end{document}\n', file=fi, append=TRUE)
102 ## In /tmp run htlatex z.tex to produce z.html
103 ## To get htlatex install the linux tex4ht package
104 ## You may also need to install the tth package
105 ## See http://biostat.mc.vanderbilt.edu/SweaveConvert
106 @
107
70108 \end{document}