Memisc test

library(devtools)
#devtools::install_github("melff/memisc/pkg")
#library(memisc)
load_all("~/R/devel/memisc/pkg")
library(magrittr)
Loading memisc
Loading required package: lattice
Loading required package: MASS
Creating a new generic function for ‘contrasts’ in package ‘memisc’
Creating a generic function for ‘contrasts<-’ from package ‘stats’ in package ‘memisc’
Creating a generic function for ‘as.ordered’ from package ‘base’ in package ‘memisc’
Creating a generic function for ‘as.factor’ from package ‘base’ in package ‘memisc’
Creating a generic function for ‘%in%’ from package ‘base’ in package ‘memisc’
Creating a generic function for ‘sample’ from package ‘base’ in package ‘memisc’
lm0 <- lm(sr ~ pop15 + pop75,              data = LifeCycleSavings)
lm1 <- lm(sr ~                 dpi + ddpi, data = LifeCycleSavings)
lm2 <- lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)

mtable123 <- mtable("Model 1"=lm0,"Model 2"=lm1,"Model 3"=lm2,
    summary.stats=c("sigma","R-squared","F","p","N"))

(mtable123 %<>% relabel(
  "(Intercept)" = "Constant",
          pop15 = "Percentage of population under 15",
          pop75 = "Percentage of population over 75",
            dpi = "Real per-capita disposable income",
           ddpi = "Growth rate of real per-capita disp. income"
  ))
Model 1Model 2Model 3
Constant 30.628***6.360***28.566***
(7.409)(1.252)(7.355)
Percentage of population under 15 −0.471**−0.461**
(0.147)(0.145)
Percentage of population over 75 −1.934−1.691
(1.041)(1.084)
Real per-capita disposable income 0.001−0.000
(0.001)(0.001)
Growth rate of real per-capita disp. income0.529*0.410*
(0.210)(0.196)
sigma 3.94.23.8
R-squared 0.30.20.3
F 8.34.55.8
p 0.00.00.0
N 505050
print(mtable123)
Calls:
Model 1: lm(formula = sr ~ pop15 + pop75, data = LifeCycleSavings)
Model 2: lm(formula = sr ~ dpi + ddpi, data = LifeCycleSavings)
Model 3: lm(formula = sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)

================================================================================
                                               Model 1    Model 2    Model 3
--------------------------------------------------------------------------------
  Constant                                    30.628***   6.360***  28.566***
                                              (7.409)    (1.252)    (7.355)
  Percentage of population under 15           -0.471**              -0.461**
                                              (0.147)               (0.145)
  Percentage of population over 75            -1.934                -1.691
                                              (1.041)               (1.084)
  Real per-capita disposable income                       0.001     -0.000
                                                         (0.001)    (0.001)
  Growth rate of real per-capita disp. income             0.529*     0.410*
                                                         (0.210)    (0.196)
--------------------------------------------------------------------------------
  sigma                                           3.9        4.2        3.8
  R-squared                                       0.3        0.2        0.3
  F                                               8.3        4.5        5.8
  p                                               0.0        0.0        0.0
  N                                              50         50         50
================================================================================
class(mtable123)
'memisc_mtable'
options(memisc.repr_html=FALSE)
getOption("memisc.repr_latex")
mtable123
TRUE
================================================================================
                                               Model 1    Model 2    Model 3
--------------------------------------------------------------------------------
  Constant                                    30.628***   6.360***  28.566***
                                              (7.409)    (1.252)    (7.355)
  Percentage of population under 15           -0.471**              -0.461**
                                              (0.147)               (0.145)
  Percentage of population over 75            -1.934                -1.691
                                              (1.041)               (1.084)
  Real per-capita disposable income                       0.001     -0.000
                                                         (0.001)    (0.001)
  Growth rate of real per-capita disp. income             0.529*     0.410*
                                                         (0.210)    (0.196)
--------------------------------------------------------------------------------
  sigma                                           3.9        4.2        3.8
  R-squared                                       0.3        0.2        0.3
  F                                               8.3        4.5        5.8
  p                                               0.0        0.0        0.0
  N                                              50         50         50
================================================================================
options(memisc.repr_html=TRUE)
show_html(mtable123)
Model 1Model 2Model 3
Constant 30.628***6.360***28.566***
(7.409)(1.252)(7.355)
Percentage of population under 15 −0.471**−0.461**
(0.147)(0.145)
Percentage of population over 75 −1.934−1.691
(1.041)(1.084)
Real per-capita disposable income 0.001−0.000
(0.001)(0.001)
Growth rate of real per-capita disp. income0.529*0.410*
(0.210)(0.196)
sigma 3.94.23.8
R-squared 0.30.20.3
F 8.34.55.8
p 0.00.00.0
N 505050
M <- diag(1:3)
rownames(M) <- letters[1:3]
colnames(M) <- letters[1:3]
M
abc
a100
b020
c003
repr_html.matrix <- function(obj) memisc:::format_html.matrix(obj)
M
a100
b020
c003
as.table(M)
  a b c
a 1 0 0
b 0 2 0
c 0 0 3
names(dimnames(M)) <- c("Row","Col")
ftable(as.table(M))
Col
Rowabc
a100
b020
c003
#repr_html.ftable <- function(obj) memisc:::format_html.ftable(obj)
N <- ftable(as.table(M))
N
Col
Rowabc
a100
b020
c003
repr_html.ftable_matrix <- function(obj) memisc:::format_html.ftable_matrix(obj)
cbind(N,N)
ColCol
abcabc
Rowa100100
b020020
c003003
class(ftable(as.table(M)))
'ftable'
#repr_html.html_elem <- function(obj) as.character(obj)
#repr_html.html_group <- function(obj) as.character(obj)

Hello <- "Hello World!"
Hello <- html("p",Hello)
style(Hello) <- c(color="white",
                  "font-size"="40px",
                  "text-align"="center")

Link <- html("a","More examples here ...",
              href="http://elff.eu/software/memisc",
              title="More examples here ...",
              style=css(color="white"))
Link <- html("p"," (",Link,")")
style(Link) <- c(color="white",
                 "font-size"="15px",
                 "text-align"="center")

Hello <- html("div",c(Hello,Link))
style(Hello) <- c("background-color"="#160666",
                  padding="20px")

Hello

Hello World!

(More examples here ...)

print(Hello)
<div style="background-color: #160666; padding: 20px;"><p style="color: white; font-size: 40px; text-align: center;">Hello World!</p><p style="color: white; font-size: 15px; text-align: center;"> (<a href="http://elff.eu/software/memisc" title="More examples here ..." style="color: white;">More examples here ...</a>)</p></div>