Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The error you show is because the output from <code>ks.test</code> is not tabular output nor in a format that <code>xtable</code> understands. The output looks like this:</p> <pre><code>&gt; x &lt;- rnorm(50) &gt; y &lt;- runif(30) &gt; # Do x and y come from the same distribution? &gt; (res &lt;- ks.test(x, y)) Two-sample Kolmogorov-Smirnov test data: x and y D = 0.46, p-value = 0.0004387 alternative hypothesis: two-sided </code></pre> <p>Which isn't really tabular. For you to get this to work with <code>ks.test</code> you'd need to write a method for <code>xtable</code> for class <code>"htest"</code> (which is what type of object is returned by <code>ks.test</code>. Several methods already exist for other types of object:</p> <pre><code>&gt; require(xtable) Loading required package: xtable &gt; methods(xtable) [1] xtable.anova* xtable.aov* [3] xtable.aovlist* xtable.coxph* [5] xtable.data.frame* xtable.glm* [7] xtable.lm* xtable.matrix* [9] xtable.prcomp* xtable.summary.aov* [11] xtable.summary.aovlist* xtable.summary.glm* [13] xtable.summary.lm* xtable.summary.prcomp* [15] xtable.table* xtable.ts* [17] xtable.zoo* Non-visible functions are asterisked </code></pre> <p>Class <code>"htest"</code> is reasonably common (it is used for most it not all of R classical tests), so I would venture that the absence of an <code>xtable.htest</code> is that the results from a hypothesis test like this don't lend themselves to tabular output - there are only two numbers of interest in the KS test output for example.</p> <p>As I said in my comment, I would just quote the test statistic <code>D</code> and the <code>p-value</code> in-line in the text.</p> <p>If you have multiple tests and want to summarise them, collect the outputs from several <code>ks.test</code> runs into a data frame and then use <code>xtable</code> on that data frame (which will work as it there is a method for that). To combine to a number of ks tests into a table (a data frame) you could do something like</p> <pre><code>df.res &lt;- data.frame(D = c(res$statistic, res$statistic), `p value` = c(res$p.value, res$p.value)) xtable(df.res) </code></pre> <p>which gives:</p> <pre><code>&gt; df.res &lt;- data.frame(D = c(res$statistic, res$statistic), + `p value` = c(res$p.value, res$p.value)) &gt; xtable(df.res) % latex table generated in R 2.15.2 by xtable 1.7-0 package % Wed Oct 31 09:19:16 2012 \begin{table}[ht] \begin{center} \begin{tabular}{rrr} \hline &amp; D &amp; p.value \\ \hline 1 &amp; 0.46 &amp; 0.00 \\ 2 &amp; 0.46 &amp; 0.00 \\ \hline \end{tabular} \end{center} \end{table} </code></pre> <p>Then look at <code>print.xtable</code> and the manual for <strong>xtable</strong> the package for details of how to format the names of the data frame etc to get nicer output in the LaTeX output.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload