Re: [Rd] Summary methods

From: Douglas Bates <bates_at_stat.wisc.edu>
Date: Tue, 10 Nov 2009 06:55:35 -0600

On Sun, Nov 8, 2009 at 2:26 PM, Doran, Harold <HDoran_at_air.org> wrote:
> I've defined the following for objects of a class called jml
>
> summary.jml <- function(object, ...){
>        tab <- cbind(Estimate = coef(object),
>                        StdError = object$se,
>                        Infit = object$Infit,
>                        Outfit = object$Outfit)
>        res <- list(call = object$call, coefficients = tab,
>                        N = nrow(object$Data), iter = object$Iterations)
>        class(res) <- "summary.jml"
>        res
> }
>
> print.summary.jml <- function(x, ...){
>   cat("Call:\n")
>   print(x$call)
>   cat("\n")
>   cat("Number of iterations to completion:", x$iter, "\n")
>   cat("Number of individuals used in estimation:", x$N, "\n")
>   cat("\n")
>   printCoefmat(x$coefficients)
>   }
>
> Use of the methods on a fitted jml object yields:
>
>> summary(aa)
> Call:
> jml2.formula(formula = ~V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8 +
>    V9 + V10, data = itemDat, bias = F)
>
> Number of iterations to completion: 6
> Number of individuals used in estimation: 486
>
>                 StdError     Infit Outfit
>  [1,] -0.380346  0.103002  1.007466 0.9935
>  [2,]  0.025939  0.104052  1.003050 1.0083
>  [3,]  2.563784  0.171174  0.941453 0.9414
>  [4,] -2.930519  0.156923  1.010786 1.0515
>  [5,]  1.139241  0.118932  0.978101 1.1424
>  [6,] -1.461751  0.111563  1.030612 1.2709
>  [7,]  0.486202  0.107986  1.008374 1.0394
>  [8,] -0.497102  0.103117  0.961431 0.9012
>  [9,] -0.486478  0.103099  1.001752 0.9829
> [10,]  1.541029  0.129214  1.010011 0.9150
>
> Two questions. First, why is the name of the first column empty instead of "Estimate" as I have specified in the summary method?

Because you are using cbind to create the table. Use data.frame instead. I think that will also help with the alignment issue.

> Second, I am struggling to get the row names of the coefficients to align with the formula call. For example, instead of
>
>                 StdError     Infit Outfit
>  [1,] -0.380346  0.103002  1.007466 0.9935
>
> I would prefer
>
>                 StdError     Infit Outfit
>  V1 -0.380346  0.103002  1.007466 0.9935
>
> This also occurs in my print method
>
> print.jml <- function(x, digits = 2, ...){
>   cat("\nCall:\n", deparse(x$call), "\n\n", sep = "")
>   cat("Coefficients:\n")
>                print.default(format(coef(x), digits = digits), print.gap=2,
>                quote = FALSE)
>   invisible(x)
>   }
>
> Which produces
>
>> win
> Call:
> jml2.default(dat = itemDat[, 1:10])
>
> Coefficients:
>             [,1]
>  [1,] -0.38034638
>  [2,]  0.02593937
>  [3,]  2.56378422
>  [4,] -2.93051899
>  [5,]  1.13924076
>  [6,] -1.46175119
>  [7,]  0.48620247
>  [8,] -0.49710150
>  [9,] -0.48647770
> [10,]  1.54102895
>
> Thank you
> Harold
>
>> sessionInfo()
> R version 2.10.0 (2009-10-26)
> i386-pc-mingw32
>
> locale:
> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] MASS_7.3-3         lme4_0.999375-32   Matrix_0.999375-31 lattice_0.17-26
> [5] MiscPsycho_1.4     statmod_1.4.1
>
> loaded via a namespace (and not attached):
> [1] grid_2.10.0  plink_1.2-2  tools_2.10.0
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 10 Nov 2009 - 13:04:24 GMT

This archive was generated by hypermail 2.2.0 : Tue 10 Nov 2009 - 16:40:31 GMT