[R] vegan and sweave using xtable

Ista Zahn izahn at psych.rochester.edu
Fri Feb 4 16:10:37 CET 2011


Hi Olga,
Here is how I would approach this problem. I hope it is instructive.

library(vegan)
data(BCI)
mod <- radfit(BCI[1,])

class(mod) #find out what mod is
methods(class="radfit") #find out what methods are available for
objects of this class. Nothing looks promising, so define a summary
method for it, based on the print method

print.radfit #look to see how the print method is defined. Copy this
function and modify it, as shown below.

summary.radfit <- function (x, digits = max(3, getOption("digits") - 2), ...)
{
    # modify the funciton to eliminate the header info
   # cat("\nRAD models, family", x$family$family, "\n")
   # cat("No. of species ", length(x$y), ", total abundance ",
   #     sum(x$y), "\n\n", sep = "")
    p <- coef(x)
    if (any(!is.na(p)))
        p <- formatC(p, format = "g", flag = " ", digits = digits)
    p <- apply(p, 2, function(x) gsub("NA", " ", x))
    aic <- sapply(x$models, AIC)
    bic <- sapply(x$models, AIC, k = log(length(x$y)))
    dev <- sapply(x$models, deviance)
    stats <- format(cbind(Deviance = dev, AIC = aic, BIC = bic),
        digits = digits, ...)
    out <- cbind(p, stats)
    #modify the funciton so it doesn't print the result
    #print(out, quote = FALSE)
    return(out) #modify the function to return the summary matrix.
}

library(xtable)
xtable(summary(mod))# enjoy the fruits of our labor!


On Fri, Feb 4, 2011 at 9:03 AM, Olga Lyashevska <olga at herenstraat.nl> wrote:
> Dear all,
>
> Using:
>
> library(vegan)
> data(BCI)
> mod <- radfit(BCI[1,])
> mod
>
> RAD models, family poisson
> No. of species 93, total abundance 448
>
>           par1      par2     par3    Deviance AIC      BIC
> Null                                   39.5261 315.4362 315.4362
> Preemption  0.042797                   21.8939 299.8041 302.3367
> Lognormal   1.0687    1.0186           25.1528 305.0629 310.1281
> Zipf        0.11033  -0.74705          61.0465 340.9567 346.0219
> Mandelbrot  100.52   -2.312    24.084   4.2271 286.1372 293.7350
>
>
> I want to include the table shown above into the latex document  (using
> xtable).
>
> library(xtable)
> xtable(mod)
> Error in UseMethod("xtable") :
>  no applicable method for 'xtable' applied to an object of class "radfit"
>
> Also is there is a way to customize the table - I want to exclude first two
> rows  of the output and make a table of:
>
>           par1      par2     par3    Deviance AIC      BIC
> Null                                   39.5261 315.4362 315.4362
> Preemption  0.042797                   21.8939 299.8041 302.3367
> Lognormal   1.0687    1.0186           25.1528 305.0629 310.1281
> Zipf        0.11033  -0.74705          61.0465 340.9567 346.0219
> Mandelbrot  100.52   -2.312    24.084   4.2271 286.1372 293.7350
>
>
> Many thanks,
> Olga
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list