LaTeX packages for R and Advanced knitr

Similar documents
Creating publication-ready Word tables in R

The nuts and bolts of Sweave/Knitr for reproducible research

k Nearest Neighbors Super simple idea! Instance-based learning as opposed to model-based (no pre-processing)

Intro to R for Epidemiologists

Data Mining - Data. Dr. Jean-Michel RICHER Dr. Jean-Michel RICHER Data Mining - Data 1 / 47

Lab #7 - More on Regression in R Econ 224 September 18th, 2018

Stat405. Tables. Hadley Wickham. Tuesday, October 23, 12

arulescba: Classification for Factor and Transactional Data Sets Using Association Rules

A Tour of Sweave. Max Kuhn. March 14, Pfizer Global R&D Non Clinical Statistics Groton

Machine Learning: Algorithms and Applications Mockup Examination

Advanced Statistics 1. Lab 11 - Charts for three or more variables. Systems modelling and data analysis 2016/2017

K-fold cross validation in the Tidyverse Stephanie J. Spielman 11/7/2017

blogr: R for blogs Shane M. Conway December 13, 2009

Outline. Installing LaTeX. Opening TeXShop. Intro to LaTeX. Intro to LaTeX interface Working with text Tabbing and tables Figures Math and equations

Introduction to R. Daniel Berglund. 9 November 2017

Linear discriminant analysis and logistic

Introduction to R and Statistical Data Analysis

Clojure & Incanter. Introduction to Datasets & Charts. Data Sorcery with. David Edgar Liebke

Package elasticsearchr

Introduction to R for Epidemiologists

A Knitr Demo. Charles J. Geyer. February 8, 2017

USE IBM IN-DATABASE ANALYTICS WITH R

A Data Explorer System and Rulesets of Table Functions

DEPARTMENT OF BIOSTATISTICS UNIVERSITY OF COPENHAGEN. Graphics. Compact R for the DANTRIP team. Klaus K. Holst

CS4618: Artificial Intelligence I. Accuracy Estimation. Initialization

In stochastic gradient descent implementations, the fixed learning rate η is often replaced by an adaptive learning rate that decreases over time,

Data analysis case study using R for readily available data set using any one machine learning Algorithm

6 Subscripting. 6.1 Basics of Subscripting. 6.2 Numeric Subscripts. 6.3 Character Subscripts

Chapter 60 The STEPDISC Procedure. Chapter Table of Contents

Work 2. Case-based reasoning exercise

Advanced Graphics in R

KTH ROYAL INSTITUTE OF TECHNOLOGY. Lecture 14 Machine Learning. K-means, knn

DATA VISUALIZATION WITH GGPLOT2. Coordinates

An Introduction to R Graphics

netzen - a software tool for the analysis and visualization of network data about

The STEPDISC Procedure

R Workshop Guide. 1 Some Programming Basics. 1.1 Writing and executing code in R

BL5229: Data Analysis with Matlab Lab: Learning: Clustering

Section 1.5: Point-Slope Form

Graphing Bivariate Relationships

Decision Trees In Weka,Data Formats

Data Visualization Using R & ggplot2. Karthik Ram October 6, 2013

LESSON 14: Box plots questions

Introduction to Artificial Intelligence

Package reghelper. April 8, 2017

Manuel Oviedo de la Fuente and Manuel Febrero Bande

CS 8520: Artificial Intelligence. Weka Lab. Paula Matuszek Fall, CSC 8520 Fall Paula Matuszek

KnitR + L A T E X paper

Package glue. March 12, 2019

Fitting Classification and Regression Trees Using Statgraphics and R. Presented by Dr. Neil W. Polhemus

Programming in R Very Short Introduction. Why Programming in R? Outline. Thomas Girke. October 1, 2010

Formellement. Exemples

Package quark. March 13, 2016

Some issues with R It is command-driven, and learning to use it to its full extent takes some time and effort. The documentation is comprehensive,

Package rococo. October 12, 2018

An Introduction to Statistical Computing in R

R for Wildlife Ecologists (Quick Reference Guide)

Programming in R. Very Short Introduction. Thomas Girke. October 1, Programming in R Slide 1/21

DATA VISUALIZATION WITH GGPLOT2. Grid Graphics

OVERVIEW OF ESTIMATION FRAMEWORKS AND ESTIMATORS

Package flextable. September 5, 2017

Robust Linear Regression (Passing- Bablok Median-Slope)

Partitioning Cluster Analysis with Possibilistic C-Means Zeynel Cebeci

Instance-Based Representations. k-nearest Neighbor. k-nearest Neighbor. k-nearest Neighbor. exemplars + distance measure. Challenges.

STAT 1291: Data Science

MULTIVARIATE ANALYSIS USING R

Scientific Programming. Lecture A07 Pandas

Model Selection Introduction to Machine Learning. Matt Gormley Lecture 4 January 29, 2018

Package flextable. December 8, 2017

k-nearest Neighbors + Model Selection

Experimental Design + k- Nearest Neighbors

Bernt Arne Ødegaard. 15 November 2018

Data Manipulation using dplyr

Hands on Datamining & Machine Learning with Weka

STATS Data Analysis using Python. Lecture 15: Advanced Command Line

Package condformat. October 19, 2017

Hsiaochun Hsu Date: 12/12/15. Support Vector Machine With Data Reduction

Visualizing high-dimensional data:

mmpf: Monte-Carlo Methods for Prediction Functions by Zachary M. Jones

Sweave Dynamic Interaction of R and L A TEX

UNSUPERVISED LEARNING IN PYTHON. Visualizing the PCA transformation

Neural Networks Laboratory EE 329 A

Python for R Users. By Chandan Routray As a part of internship at

Hypothesis Test Exercises from Class, Oct. 12, 2018

Package mason. July 5, 2018

Package rococo. August 29, 2013

Quant II Recitation. Drew Dimmery January 31, 2014

Among those 14 potential explanatory variables,non-dummy variables are:

Analysis and Latent Semantic Indexing

Chuck Cartledge, PhD. 20 January 2018

Introduction to R. Dr. Emile R. Chimusa Department of Integrative Biomedical Sciences University of Cape Town. May 9, 2016

Package shinyaframe. November 26, 2017

36-402/608 HW #1 Solutions 1/21/2010

Chapter II Multiple Correspondance Analysis (MCA)

STENO Introductory R-Workshop: Loading a Data Set Tommi Suvitaival, Steno Diabetes Center June 11, 2015

2. Navigating high-dimensional spaces and the RnavGraph R package

Using knitr and pandoc to create reproducible scientific reports

Package sqlscore. April 29, 2018

Introduction to R, Github and Gitlab

A Basic Example of ANOVA in JAGS Joel S Steele

Transcription:

LaTeX packages for R and Advanced knitr Iowa State University April 9, 2014

More ways to combine R and LaTeX Additional knitr options for formatting R output: \Sexpr{}, results='asis' xtable - formats R tables and data frames as LaTeX tables stargazer - displaying R models in LaTeX Hmisc - display generic R objects in LaTeX

Referencing R objects in the LaTeX document x <- 15 y <- rnorm(10, 1) Often, we want to reference numerical results in the text: reporting summary statistics, number of observations, p-values... we don't want to have to replace those manually. \Sexpr{R code} lets you reference your R data inline.

Referencing R objects in the LaTeX document \Sexpr{R code} lets you reference your R data inline. For example, $x=\sexpr{x}$ and $\overline{y}=\sexpr{mean(y)}$ produces the output x = 15 and y = 0.7226 when compiled in a knitr document. As long as the code chunk you are referencing precedes the \Sexpr{} command, knitr will be able to ll in the blanks for you!

Creating LaTeX code within R R has lots of packages to produce LaTeX formatted R objects: xtable - make nice tables stargazer - regression model tables Hmisc - make generic R objects into LaTeX-formatted objects This one is a bit higher-level texreg - model output miscfuncs - more latex tables reporttools - descriptive statistics We're only going to talk about the rst 3, but there are many other packages out there to do similar things.

Creating LaTeX Tables with xtable library(xtable) data(iris) xtable(head(iris)) Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.10 3.50 1.40 0.20 setosa 2 4.90 3.00 1.40 0.20 setosa 3 4.70 3.20 1.30 0.20 setosa 4 4.60 3.10 1.50 0.20 setosa 5 5.00 3.60 1.40 0.20 setosa 6 5.40 3.90 1.70 0.40 setosa

Creating LaTeX Tables with xtable?xtable?print.xtable print(xtable(head(iris), caption="iris dataset included with R"), include.rownames=false, size="footnotesize") Sepal.Length Sepal.Width Petal.Length Petal.Width Species 5.10 3.50 1.40 0.20 setosa 4.90 3.00 1.40 0.20 setosa 4.70 3.20 1.30 0.20 setosa 4.60 3.10 1.50 0.20 setosa 5.00 3.60 1.40 0.20 setosa 5.40 3.90 1.70 0.40 setosa Table : Iris dataset included with R

Your Turn Modify blank.rnw to do the following: Use the digits option in xtable to display only one decimal for the Sepal measurements Change the table caption Set the table reference label to "irisdata" and reference it in a sentence outside the code chunk Remove the row number from the table display library(xtable) data(iris) xtable(head(iris), digits=c(0, 1, 1, 2, 2, 0))

stargazer: Latex and R Models x <- seq(0, 10,.5) y <- x+rnorm(length(x)) data <- data.frame(x=x, y=y) model <- lm(y~x, data=data) library(stargazer) stargazer(model)

stargazer: Latex and R Models x Dependent variable: y 0.939 (0.058) Constant 0.446 (0.342) Observations 21 R 2 0.931 Adjusted R 2 0.928 Residual Std. Error 0.811 (df = 19) F Statistic 258.100 (df = 1; 19) Note: p<0.1; p<0.05; p<0.01

stargazer: Latex and R Models intercept.model <- lm(y~x, data=data) nointercept.model <- lm(y~0+x, data=data) stargazer(intercept.model, nointercept.model, float=f, single.row=true, font.size="scriptsize", object.names=t, model.numbers=f) intercept.model Dependent variable: y nointercept.model x 0.939 (0.058) 1.004 (0.031) Constant 0.446 (0.342) Observations 21 21 R 2 0.931 0.982 Adjusted R 2 0.928 0.981 Residual Std. Error 0.811 (df = 19) 0.825 (df = 20) F Statistic 258.100 (df = 1; 19) 1,063.000 (df = 1; 20) Note: p<0.1; p<0.05; p<0.01

Your Turn Using the iris data: Model sepal width by petal width; report the results in a LaTeX table using stargazer Add a caption to your table using the title= option Change the independent variable label to read Petal Width" Hint: dep.var.labels="" Change the dependent variable label to Sepal Width" Hint: covariate.labels="" In the text below the table, report and discuss the correlation between Sepal and Petal Width using \Sexpr{}. data(iris) model <- lm(iris$sepal.width~iris$petal.width)?stargazer Remember to turn messages o!

Hmisc: Latex and R Objects Workhorse function: latex() Very exible - handles S3 and S4 classes, lists, data frames, matrices... Lots of options for formatting Has a preview function Other packages are easier to use

Hmisc: Latex and R Objects library(hmisc) my.mean <- function(x){ sum(x, na.rm=true)/length(x) } latex(my.mean, file="") my.mean function (x) { sum(x, na.rm = TRUE)/length(x) }

Hmisc: Latex and R Objects Functions can also be done with knitr directly: my.mean function(x) sum(x, na.rm=true)/length(x)

Hmisc: Latex and R Objects Output specic model information with latex() model <- lm(y~x, data=data) model.tab <- cbind(terms=c("intercept", "x"), Estimates=round(model$coefficients, 3), SE=round(sqrt(diag(vcov(model))), 3)) rownames(model.tab) <- NULL latex(model.tab, file="") terms Estimates SE Intercept 0.446 0.342 x 0.939 0.058