Creating an Hmisc Table

Just start with R and try to figure out what works for my needs when it comes to creating pivot tables. I'm used to custom tables in SPSS, and the CrossTable function in the gmodels package gets me almost where I need it; not to mention that it’s easy to navigate for someone just starting out in R.

However, it seems that the Hmisc table is very good at creating various resumes and exporting to LaTex (ultimately what I need to do).

My questions are: 1) can you easily create the table below on the Hmsic page? 2) if yes, can I interact with variables (2 in a column)? and finally 3) can I access the p-values ​​of the significance tests (chi square).

Thanks in advance,

Brock

   Cell Contents
|-------------------------|
|                   Count |
|             Row Percent |
|          Column Percent |
|-------------------------|

Total Observations in Table:  524 

             | asq[, 23] 
    asq[, 4] |        1  |        2  |        3  |        4  |        5  | Row Total | 
-------------|-----------|-----------|-----------|-----------|-----------|-----------|
           0 |       76  |       54  |       93  |       46  |       54  |      323  | 
             |   23.529% |   16.718% |   28.793% |   14.241% |   16.718% |   61.641% | 
             |   54.286% |   56.250% |   63.265% |   63.889% |   78.261% |           | 
-------------|-----------|-----------|-----------|-----------|-----------|-----------|
           1 |       64  |       42  |       54  |       26  |       15  |      201  | 
             |   31.841% |   20.896% |   26.866% |   12.935% |    7.463% |   38.359% | 
             |   45.714% |   43.750% |   36.735% |   36.111% |   21.739% |           | 
-------------|-----------|-----------|-----------|-----------|-----------|-----------|
Column Total |      140  |       96  |      147  |       72  |       69  |      524  | 
             |   26.718% |   18.321% |   28.053% |   13.740% |   13.168% |           | 
-------------|-----------|-----------|-----------|-----------|-----------|-----------|
+3
2

gmodels CrossTable, , SPSS SAS. :

library(gmodels)  # run install.packages("gmodels") if you haven't installed the package yet
x <- sample(c("up", "down"), 100, replace = TRUE)
y <- sample(c("left", "right"), 100, replace = TRUE)
CrossTable(x, y, format = "SPSS")

, , , SPSS-y.:)

+4

SPSS, Deducer (http://www.deducer.org). :

> library(Deducer)
> data(tips)
> tables<-contingency.tables(
+ row.vars=d(smoker),
+ col.vars=d(day),data=tips)
> tables<-add.chi.squared(tables)
> print(tables,prop.r=T,prop.c=T,prop.t=F)
================================================================================================================

               ==================================================================================               
                                   ========== Table: smoker by day ==========                                   
                       | day 
                smoker |      Fri  |      Sat  |      Sun  |     Thur  | Row Total | 
-----------------------|-----------|-----------|-----------|-----------|-----------|
          No  Count    |        4  |       45  |       57  |       45  |      151  | 
              Row %    |    2.649% |   29.801% |   37.748% |   29.801% |   61.885% | 
              Column % |   21.053% |   51.724% |   75.000% |   72.581% |           | 
-----------------------|-----------|-----------|-----------|-----------|-----------|
         Yes  Count    |       15  |       42  |       19  |       17  |       93  | 
              Row %    |   16.129% |   45.161% |   20.430% |   18.280% |   38.115% | 
              Column % |   78.947% |   48.276% |   25.000% |   27.419% |           | 
-----------------------|-----------|-----------|-----------|-----------|-----------|
          Column Total |       19  |       87  |       76  |       62  |      244  | 
              Column % |    7.787% |   35.656% |   31.148% |   25.410% |           | 



            Large Sample                                                       
       Test Statistic    DF p-value | Effect Size est.  Lower (%)   Upper (%)  
Chi Squared 25.787       3  <0.001  | Cramer V  0.325 0.183 (2.5) 0.44 (97.5)
-----------





================================================================================================================

html xxtable:

> library(xtable)
> xtable(drop(extract.counts(tables)[[1]]))
> test <- contin.tests.to.table((tables[[1]]$tests))
> xtable(test)
+3

Source: https://habr.com/ru/post/1756842/


All Articles