Package {TRSbook}


Type: Package
Title: Companion to the Book "The R Software"
Version: 1.0.4
Date: 2026-08-5
Description: Functions and datasets for readers of the book "The R Software: Fundamentals of Programming and Statistical Analysis" by Lafaye de Micheaux, Drouilhet and Liquet (2013) <doi:10.1007/978-1-4614-9020-3>.
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
LazyLoad: yes
Depends: xtable, RColorBrewer, gdata, IndependenceTests
NeedsCompilation: yes
Packaged: 2026-08-05 12:54:01 UTC; lafaye
Author: Pierre Lafaye De Micheaux [aut, cre], Remy Drouilhet [aut], Benoit Liquet [aut]
Maintainer: Pierre Lafaye De Micheaux <lafaye@unsw.edu.au>
Repository: CRAN
Date/Publication: 2026-08-23 10:41:08 UTC

Weight at Birth

Description

This study focused on risks associated with low weight at birth; the data were collected at the Baystate Medical Centre, Massachusetts, in 1986. Physicians have been interested in low weight at birth for several years, because underweight babies have high rates of infant mortality and infant anomalies. The behaviour of the mother-to-be during pregnancy (diet, smoking habits) can have a significant impact on the chances of having a full-term pregnancy, and thus of giving birth to a child of normal weight. The data file includes information on 189 women (identification number: ID) who came to the centre for consultation. Weight at birth is categorized as low if the child weighs less than 2,500 g.

Usage

data(BIRTH.WEIGHT)

Format

A data frame with 189 observations measured on the following 11 variables.

ID

Numeric. Identification.

AGE

Numeric. Age of mother.

LWT

Numeric. Weight of mother at last menstrual period.

RACE

1=white, 2=black, 3=other. Race of mother.

SMOKE

Yes=1, No=0. Smoking during pregnancy.

PTL

0=none, 1=one, 2=two, etc. Number of premature births in medical history.

HT

Yes=1, No=0. Medical history of hypertension.

UI

Yes=1, No=0. Uterine irritability.

FVT

0=none, 1=one, etc. Number of medical consultations during first trimester

BWT

Numeric. Grams.

LOW

Yes=1, No=0. Weight at birth less than 2,500g

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

Source

https://www.biostatisticien.eu/springeR/

Examples

data(BIRTH.WEIGHT)
str(BIRTH.WEIGHT) 

Body Mass Index of children

Description

This data set comes from an epidemiologic study analyzed by a team from the Institut de sante publique d'epidemiologie et de developpement (ISPED) de Bordeaux. A sample of 152 children (3 or 4 years old) in their first year of kindergarten in schools in Bordeaux (Gironde, SouthWest France) underwent a physical check-up in 1996-1997.

Usage

data(BMI.CHILD)

Format

A data frame with 152 observations measured on the 6 following variables:

GENDER

a factor with levels F and M

zep

a factor with levels Y and N

weight

numeric

years

numeric

months

numeric

height

numeric

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

Source

https://www.biostatisticien.eu/springeR/

Examples

data(BMI.CHILD)
str(BMI.CHILD) 

Study Case of Myocardial Infarction

Description

The study for which the following data were collected aimed at examining whether women who use or have used oral contraceptives are at a higher risk of myocardial infarction. The sample includes 149 women who had myocardial infarction (cases) and 300 women who did not (controls). The main exposure factor is usage of oral contraceptives; the data also include age, weight, height, tobacco consumption, hypertension and family history of cardiovascular diseases.

Usage

data(INFARCTION)

Format

A data frame with 449 observations measured on the following 10 variables:

NUMBER

Identification.

infarct

0 = controls; 1 = cases. Myocardial infarction.

co

0 = never; 1 = yes. Usage of oral contraceptives.

tobacco

0 = no; 1 = smoker; 2 = fromer smoker. Tobacco usage.

age

Age in years.

weight

Weight in kg.

height

Height in cm.

atcd

0 = no; 1 = yes. Family history of cardiovascular diseases.

hta

0 = no; 1 = yes. Hypertension.

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

Source

https://www.biostatisticien.eu/springeR/

Examples

data(INFARCTION)
str(INFARCTION) 

Intima-Media Thickness

Description

Atherosclerosis is the main cause of death for men above 35 and women above 45 in most developed countries. It is a thickening and hardening of internal artery walls. One of its consequences is myocardial infarction. An artery wall is made of three layers; innermost to outermost, they are called intima, media and adventitia. Intima-media thickness is a marker of atherosclerosis. It was measured by ultra- sonography on a sample of 110 subjects in 1999 in Bordeaux hospitals. Information on the main risk factors was also collected.

Usage

data(INTIMA.MEDIA)

Format

A data frame with 110 observations measured on the 9 following variables:

GENDER

1=male, 2=female. Gender.

AGE

Age (in years) at date of consultation.

height

Hieght in cm.

weight

Weight in kg.

tobacco

0=non smoker, 1=former smoker, 2=smoker. Smoking status.

packyear

Number of packs per year. Estimation of tobacco consumption for smokers and former smokers.

SPORT

0=no, 1=yes. Physicial activity.

measure

Intima-media thickness in cm

alcohol

0=non-drinker, 1=occasional drinker, 2=regular drinker. Alcohol consumption.

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

Source

https://www.biostatisticien.eu/springeR/

Examples

data(INTIMA.MEDIA)
str(INTIMA.MEDIA) 

Diet of Elderly People

Description

A sample of 226 elderly people living in Bordeaux (Gironde, South-West France) were interviewed in 2000 for a nutritional study.

Usage

data(NUTRIELDERLY)

Format

A data frame with 226 observations measured on the 13 following variables:

gender

2 = female; 1 = male

situation

1 = single; 2 = living with spouse; 3 = living with family; 4 = living with someone else; Family status.

tea

Number of cups. Daily consumption of tea.

coffee

Number of cups. Daily consumption of coffee

height

Height in cm.

weight

Weight in cm.

age

Age in years at date of interview.

meat

0 = never; 1 = less than once a week; 2 = Once a week; 3 = 2/3 times a week; 4 = 4/6 times a week; 5 = every day. Consumption of meat.

fish

Idem. Consumption of fish.

raw_fruits

Idem. Consumption of raw fruits.

cooked_fruits_veg

Idem. Consumption of cooked fruits and vegetables.

chocol

Idem. Consumption of chocolate.

fat

1 = butter; 2 = margarine; 3 = peanut oil; 4 = sunflower oil; 5 = olive oil; 6 = mix of vegetable oils (e.g., Isio4); 7 = colza oil; 8 = duck or goose fat. Type of fat used for cooking.

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

Source

https://www.biostatisticien.eu/springeR/

Examples

data(NUTRIELDERLY)
str(NUTRIELDERLY) 

Package illustrating the book: The R Software

Description

This package enables one to use some functions used in the book:The R Software, Fundamentals of Programming and Statistical Analysis, Springer, 2014. One can also find the datasets used in the book.

Details

Package: TheRSoftware
Type: Package
Version: 1.0
Date: 2014-02-04
License: GPL(>=2.0)
LazyLoad: yes

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Book: The R Software, Fundamentals of Programming and Statistical Analysis, Springer, 2014


Address of vector

Description

Object representing an address of numeric vector

Usage

VectorAddr(x)

Arguments

x

Vector.

Value

An object of class VectorAddr.

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 9 (Managing Sessions) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

Examples


x <- c(8L,9L)
addr <- VectorAddr(x)		# Gets the address of the first
                            # box of the 64-box block where x
                            # is stored.
addr
update(addr,6L) # Write the integer 6 at this address.
x
update(addr+4L,7L) # An integer is coded over 4 bytes,
                      # hence increment the address by 4 to
                      # get to x[2].
x
x <- c(12.8,4.5)
x
addr <- VectorAddr(x)		# Get the address of the first box
                            # of the 128-box block where x is
                            # stored.
update(addr,6.2)
x
update(addr+8L,7.1) # A double is coded over 8 bytes.
x


Adding arrows on statistical plots.

Description

This function add an arrow on the extremities of the axes of a plot

Usage

arrowaxis(x = TRUE, y = TRUE)

Arguments

x

Logical. Default value TRUE indicates an arrow on the x-axis

y

Logical. Default value TRUE indicates an arrow on the y-axis

Value

No return value, called for side effects. The function adds an axis with arrows to the current plot.

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 11 (Descriptive Statistics) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

Examples

curve(cos(x),xlim=c(-10,10))
arrowaxis()

Bar charts

Description

Pretty bar charts

Usage

barchart(x, col, my.title, pareto = FALSE, freq.cumul = FALSE, family = "Courier")

Arguments

x

qualitative variable

col

vector of characters for the color of each modality

my.title

character. Title of the plot

pareto

logical. TRUE for a Pareto diagram. Default os FALSE

freq.cumul

logical. TRUE to add a curve of cumulative frequencies. By default freq.cumul is FALSE

family

font family for the title. Default is "Courier". Another choice can be, e.g., "HersheyScript"

Value

A plot

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 11 (Descriptive Statistics) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

See Also

barplot

Examples

data(NUTRIELDERLY)
attach(NUTRIELDERLY)
fat <- as.factor(fat)
col <- c("yellow","yellow2","sandybrown","orange",
   "darkolivegreen","green","olivedrab2","green4")
barchart(fat,col,pareto=TRUE)
detach(NUTRIELDERLY)

Decimal representation of a binary number

Description

To compute the decimal representation of a number written in a binary format

Usage

bin2dec(x)

Arguments

x

Numeric. Number in binary format written only with 0s and 1s. See Example below.

Value

Decimal representation of the number x

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 5 (Data Manipulation, Functions) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

Examples

bin2dec(1010.101)

Pie chart

Description

A variant of the pie function

Usage

camembert(x, col = NULL, family="Courier")

Arguments

x

qualitative variable

col

vector of characters for the color of each modality

family

font family for the title. Default is "Courier". Another choice can be, e.g., "HersheyScript"

Value

A pie chart

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 11 (Descriptive Statistics) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

See Also

pie

Examples

data(NUTRIELDERLY)
attach(NUTRIELDERLY)
require("RColorBrewer")
col <- brewer.pal(8,"Pastel2")
camembert(fat,col)
detach(NUTRIELDERLY)

Test of the correlation coefficient

Description

Test of the correlation coefficient between two quantitative variables

Usage

cor0.test(x, y, rho0 = 0, alternative = c("two.sided", "less", "greater"))

Arguments

x

numeric vector

y

numeric vector

rho0

numeric indicating the value of the correlation coefficient under the null. Default is rho0 = 0

alternative

Alternative hypothesis for the test. Either two sided ("two.sided"), one sided to the left ("less") or one sided to the right ("greater"). Default is "two.sided".

Value

Returns a list:

statistic

Value of the test statistic

p.value

p-value of the test

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 13 (Confidence Intervals and Hypothesis Testing) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

See Also

cor.test

Examples

data(BMI.CHILD)
attach(BMI.CHILD)
cor0.test(weight,height)
detach(BMI.CHILD)

A cross chart

Description

A cross chart displays for each observation a smal cross above the associated modality

Usage

crosschart(x, my.title, col,family="Courier")

Arguments

x

qualitative variable

my.title

character. title of the plot

col

vector of characters for the color of each modality

family

font family for the title. Default is "Courier". Another choice can be, e.g., "HersheyScript"

Value

A cross chart

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 11 (Descriptive Statistics) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

Examples

data(NUTRIELDERLY)
attach(NUTRIELDERLY)
situation <- as.factor(situation)
levels(situation) <- c("single","couple","family","other")
crosschart(situation,col=c("orange","darkgreen","black","tan"))
detach(NUTRIELDERLY)

Binary representation of a decimal number

Description

To compute the binary representation of a number written in a decimal format

Usage

dec2bin(x,prec=52)

Arguments

x

Numeric. Number in a decimal format.

prec

Integer. Precision desired.

Value

Binary representation of the number x

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 5 (Data Manipulation, Functions) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

Examples

dec2bin(10.625,3)

A flashy scatter plot

Description

This function tries to make a nicer plot than the one given by the plot() function for two quantitative variables

Usage

flashy.plot(x,y,my.factor, family = "Courier",xlab="",ylab="")

Arguments

x

numeric vector

y

numeric vector

my.factor

factor

family

font family for the title. Default is "Courier". Another choice can be, e.g., "HersheyScript"

xlab

character. x label

ylab

character. y label

Value

A flashy scatter plot

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 11 (Descriptive Statistics) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

See Also

plot

Examples

data(NUTRIELDERLY)
attach(NUTRIELDERLY)
gender <- as.factor(gender)
levels(gender) <- c("Male","Female")
flashy.plot(weight,height,gender,xlab="Height",ylab="Weight")
detach(NUTRIELDERLY)

Retrieve the address in memory of a variable

Description

Retrieve the address in memory of a numeric variable

Usage

getaddr(x)

Arguments

x

numeric

Value

Integer value of the address of x

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 9 (Managing Sessions) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

Examples


x <- c(8L,9L)
addr <- getaddr(x) # Gets the address of the first
                            # box of the 64-box block where x
                            # is stored.
addr
writeaddr(addr,6L) # Write the integer 6 at this address.
x
writeaddr(addr+4L,7L) # An integer is coded over 4 bytes,
                      # hence increment the address by 4 to
                      # get to x[2].
x
x <- c(12.8,4.5)
x
addr <- getaddr(x) # Get the address of the first box
                            # of the 128-box block where x is
                            # stored.
writeaddr(addr,6.2)
x
writeaddr(addr+8L,7.1) # A double is coded over 8 bytes.
x


Moore Penrose inverse

Description

Computes the Moore Penrose inverse of a matrix

Usage

mpinv(M,eps=1e-13)

Arguments

M

a matrix

eps

real precision

Value

The Moore-Penrose inverse of M

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 10 (Basic Mathematics: Matrix Operations, Integration, and Optimization) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

Examples

A <- matrix(c(2,3,5,4),nrow=2,ncol=2)
solve(A)
mpinv(A)
B <- matrix(c(4,2,8,4),nrow=2,ncol=2)
# solve(B) # gives an error.
mpinv(B)

Test of a variance

Description

Comparing the theoretical variance with a reference value

Usage

sigma2.test(x, alternative = "two.sided", var0 = 1, conf.level = 0.95)

Arguments

x

numeric vector

alternative

Alternative hypothesis for the test. Either two sided ("two.sided"), one sided to the left ("less") or one sided to the right ("greater"). Default is "two.sided".

var0

value of reference for the variance

conf.level

confidence level

Value

Returns a list:

statistic

Value of the test statistic

parameter

degrees of freedom

p.value

p-value of the test

conf.int

confidence interval

estimate

sample variance

null.value

value of reference for the variance

alternative

Alternative hypothesis for the test

method

"One-sample Chi-squared test for given variance"

data.name

name of the data set

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 13 (Confidence Intervals and Hypothesis Testing) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

Examples

data(NUTRIELDERLY)
sigma2.test(NUTRIELDERLY$weight,conf.level=0.9)$conf

Comparing statistically two correlation coefficients

Description

Test of the equality of two correlation coefficients

Usage

twosample.cor.test(x1, y1, x2, y2, alpha = 0.05,alternative =
c("two.sided", "less", "greater"))

Arguments

x1

x1 is a numeric vector associated to y1

y1

y1 is a numeric vector associated to x1

x2

x2 is a numeric vector associated to y2

y2

y2 is a numeric vector associated to x2

alpha

significance level of the test

alternative

Alternative hypothesis for the test. Either two sided ("two.sided"), one sided to the left ("less") or one sided to the right ("greater"). Default is "two.sided".

Value

Returns a list:

statistic

Value of the test statistic

p.value

p-value of the test

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 13 (Confidence Intervals and Hypothesis Testing) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

See Also

cor0.test

Examples

data(BMI.CHILD)
attach(BMI.CHILD)
indf <- which(GENDER=="F")  # To  retrieve indices of the females.
indm <- which(GENDER=="M")  # To retrieve indices of the males.
twosample.cor.test(height[indf],weight[indf],
                   height[indm],weight[indm])
detach(BMI.CHILD)

Writing a value at some memory address

Description

Writing a value at some memory address

Usage

writeaddr(addr,newval)

Arguments

addr

Integer value. Address in memory.

newval

New value to write at this address.

Value

Nothing is returned.

Author(s)

Lafaye de Micheaux Pierre <lafaye@unsw.edu.au>, Remy Drouilhet <Remy.Drouilhet@upmf-grenoble.fr>, Liquet Benoit <b.liquet@uq.edu.au>

References

Chapter 9 (Managing Sessions) from the book: The R Software, Fundamentals of Programming and Statistical Analysis

Examples


x <- c(8L,9L)
addr <- getaddr(x) # Gets the address of the first
                            # box of the 64-box block where x
                            # is stored.
addr
writeaddr(addr,6L) # Write the integer 6 at this address.
x
writeaddr(addr+4L,7L) # An integer is coded over 4 bytes,
                      # hence increment the address by 4 to
                      # get to x[2].
x
x <- c(12.8,4.5)
x
addr <- getaddr(x) # Get the address of the first box
                            # of the 128-box block where x is
                            # stored.
writeaddr(addr,6.2)
x
writeaddr(addr+8L,7.1) # A double is coded over 8 bytes.
x