Category: simulation

The email wasn’t a challenge but a simple question: Is it possible to run a multivariate analysis in multiple sites? I was going to answer yes, of course, and leave it there but it would be a cruel, non-satisfying answer. We can get a better handle of the question if we use a simple example; let’s assume that we have two traits (call them tree stem diameter and stem density) assessed in two sites (localities).

Because this is genetics we have a family structure, let’s say half-siblings so we only half the mother in common, and we will ignore any experimental design features to keep things simple. We have 100 families, with 30 trees each, in sites A and B, for a total of 6,000 trees (100 x 30 x 2). The data could look like this:

1

2

3

4

5

6

7

8

9

site family tree diam dens

A1120398

A1219400

...

A1003024375

...

B1125396

...

B1003023403

We can also think of a trait measured in two sites as separate, but correlated, traits. For example, diameter in site 1 (diam1) is a different variable from diameter in site 2 (diam 2). So now we have four response variables (diam1, dens1, diam2, dens2), two of which have only missing values in a given site:

1

2

3

4

5

6

7

8

9

site family tree diam1 dens1 diam2 dens2

A1120398NA NA

A1219400NA NA

...

A1003024375NA NA

...

B11NA NA25396

...

B10030NA NA23403

All variables are correlated at the genetic level with an unstructured G covariance matrix, while at the residual level are only correlated within-site (same tree was assessed for both traits), but there is zero correlation between sites, because one could be assessed near Christchurch, while the other near Dunedin, for example.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

###

### Data generation

###

# Simulate 100 half-sib families with 30 trees each

# for the four traits in two sites

n.fam<-100

n.prog<-30

n.trait<-4

n.site<-2

# Couple of variance matrices,

# G is for additive genetic effects

# R is for residuals

# All variances are assumed equal to 1 without loss

# of generality

G<-matrix(c(1,0.7,0.5,0.3,

0.7,1,0.2,0.1,

0.5,0.2,1,0.8,

0.3,0.1,0.8,1),4,4)

R<-matrix(c(1,0.3,0,0,

0.3,1,0,0,

0,0,1,0.2,

0,0,0.2,1),4,4)

# Between-family variances account for 1/4 of additive

# genetic effects. Within-family account for 3/4 of

# additive + residual.

# We also get the Cholesky decomposition in the same step

BFL<-chol(1/4*G)

WFL<-chol(3/4*G+R)

# Simulate random family effects for four traits

# Simulate random family effects for four traits

fam.eff<-t(BFL)%*%matrix(rnorm(n.fam*n.trait),

n.trait,n.fam)

fam.eff<-t(fam.eff)# This is 100 x 4

tre.eff<-t(WFL)%*%matrix(rnorm(n.prog*n.fam*n.trait),

n.trait,n.prog*n.fam)

tre.eff<-t(tre.eff)# This is 3000 x 4

# Expand family effects matrix (n.prog each) to match

# dimension of tree effects

pheno<-fam.eff[rep(1:dim(fam.eff)[1],each=n.prog),]+tre.eff

# Now to 2 sites

pheno2s<-matrix(NA,n.prog*n.fam*n.site,n.trait)

colnames(pheno2s)<-c('diam1','dens1','diam2','dens2')

pheno2s[1:3000,1:2]<-pheno[1:3000,1:2]

pheno2s[3001:6000,3:4]<-pheno[1:3000,3:4]

# Creating data set. Family and tree are shamelessly recycled

sim.data<-data.frame(site=factor(rep(c('A','B'),each=n.fam*n.prog)),

family=factor(rep(1:n.fam,each=n.prog)),

tree=factor(1:30),

pheno2s)

Some neat things:

Data simulation relies on Cholesky decomposition, as explained in this post over a year ago (time flies!). Generation is a bit more complex this time because we have to account for two, rather than one, covariance structures.

Another point with data simulation is that one could generate one set of correlated values at the time by using something like t(BFL) %*% diag(rnorm(trait), 3) and loop it or use apply(). This would require much less memory but would also be much slower.

We need to repeat each line of the family effects matrix 30 times so we can add to the individual tree effects. Often we use indexing in matrices or data frames to extract a few rows. Instead here I’m using to repeat a given number of times each row by indexing with rep().

If we show observations 2990 to 3010 (last 10 for site A and first 10 for site B) we can see the pattern of observations below, which will have the required structure to have a US (or heterogeneous variance correlation matrix) for G and a block diagonal matrix for R. By the way, one could also have block diagonal matrices with repeated measurements, although probably with a different correlation structure:

For the analysis we will use ASReml, which is the Pro option if you work in a breeding program and require solving much larger systems of equations than this tiny example (say 50-100 traits, large pedigrees, etc). Another option for playing with this small data set would be to use MCMCglmm, which also allows for multivariate evaluation of linear mixed models.

In model 1 each of the variances was supposed to be ~0.25 (1/4 * 1) and the residual variances ~1.75 (3/4*1 + 1). Once we move to model 2 we also get values similar to the correlations we were trying to simulate. And this is the end of the long answer.

P.S. If, for some bizarre reason, you would like to use SAS for this type of analyses, Fikret Isik has proc mixed code to run multivariate genetic analyses.

I’ve ignored my quantitative geneticist side of things for a while (at least in this blog) so this time I’ll cover some code I was exchanging with a couple of colleagues who work for other organizations.

It is common to use diallel mating designs in plant and tree breeding, where a small number of parents acts as both males and females. For example, with 5 parents we can have 25 crosses, including reciprocals and selfing (crossing an individual with itself). Decades ago this mating design was tricky to fit and, considering an experimental layout with randomized complete blocks, one would have something like y = mu + blocks + dads + mums + cross + error. In this model dads and mums were estimating a fraction of the additive genetic variance. With the advent of animal model BLUP, was possible to fit something like y = mu + blocks + individual (using a pedigree) + cross + error. Another less computationally demanding alternative (at least with unrelated parents) is to fit a parental model, overlaying the design matrices for parents with something like this y = mu + blocks + (dad + mum) + cross + error.

The following code simulate data for a a diallel trial with three replicates and runs a parental model with ASReml. Later I expand the analysis building the matrices by hand.

How is the matrix overlay working? We can replicate the calculations used by ASReml by building the matrices from scratch and reusing the variance components, so we avoid the nastiness of writing code for residual maximum likelihood. Once I build the basic matrices I use the code from my How does a linear mixed model look like? post.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

# Building incidence matrices for males and females

Zmales<-model.matrix(~dad-1,data=trial)

Zfemales<-model.matrix(~mum-1,data=trial)

# and() in ASReml overlays (i.e. sums) the matrices

# (Notice that this creates 0s, 1 and 2s in the design matrix)

Zparents<-Zmales+Zfemales

Zparents[1:6,]

# dad1 dad2 dad3 dad4 dad5

#1 2 0 0 0 0

#2 1 1 0 0 0

#3 1 0 1 0 0

#4 1 0 0 1 0

#5 1 0 0 0 1

#6 1 1 0 0 0

# Design matrices from other factors

Zblocks<-model.matrix(~block-1,data=trial)

Zmates<-model.matrix(~mate-1,data=trial)

# Creating y, X and big Z matrices to solve mixed model equations

y<-trial$yield

X<-matrix(1,nrow=75,ncol=1)

Z<-cbind(Zblocks,Zparents,Zmates)

# Building covariance matrices for random effects

# Using the variance components from the ASReml model

G=diag(c(rep(3.861892e-01,3),

rep(6.246930e+00,5),

rep(1.364461e-05,25)))

R=diag(2.972722e+01,75,75)

Rinv=solve(R)

# Components of C

XpX=t(X)%*%Rinv%*%X

ZpZ=t(Z)%*%Rinv%*%Z

XpZ=t(X)%*%Rinv%*%Z

ZpX=t(Z)%*%Rinv%*%X

Xpy=t(X)%*%Rinv%*%y

Zpy=t(Z)%*%Rinv%*%y

# Building C * [b a] = RHS

C=rbind(cbind(XpX,XpZ),

cbind(ZpX,ZpZ+solve(G)))

RHS=rbind(Xpy,Zpy)

blup=solve(C,RHS)

blup

# These results are identical to the ones

# produced by ASReml

#dad1 1.780683e+00

#dad2 -2.121174e+00

#dad3 3.151991e+00

#dad4 -1.473620e+00

#dad5 -1.337879e+00

The overlay matrix Zparents is double the actual value we should use:

1

2

3

4

5

6

7

8

9

Zparents2<-0.5*(Zmales+Zfemales)

Zparents2[1:6,]

# dad1 dad2 dad3 dad4 dad5

#1 1.0 0.0 0.0 0.0 0.0

#2 0.5 0.5 0.0 0.0 0.0

#3 0.5 0.0 0.5 0.0 0.0

#4 0.5 0.0 0.0 0.5 0.0

#5 0.5 0.0 0.0 0.0 0.5

#6 0.5 0.5 0.0 0.0 0.0

Repeating the analyses ‘by hand’ using Zparents2 to build the Z matrix results in the same overall mean and block effects, but the predicted breeding values for parents when using Zparents are 0.7 of the predicted breeding values for parents when using Zparents2. I may need to refit the model and obtain new variance components for parents when working with the correct overlaid matrix.

Suicide is a tragic and complex problem. This week New Zealand’s Chief Coroner released its annual statistics on suicide, which come with several tables and figures. One of those figures refers to monthly suicides in the Christchurch region (where I live) and comes with an interesting comment:

Suicides in the Christchurch region (Timaru to Kaikoura) have risen from 67 (2010/11) to 81 (2011/12). The average number of suicides per year for this region over the past four years is 74. The figure of 67 deaths last year reflected the drop in suicides post-earthquake. The phenomenon of a drop in the suicide rate after a large scale crisis event, such as a natural disaster, has been observed elsewhere. [my emphasis]

‘Provisional Suicide deaths in relation to the Christchurch earthquakes’ this is the original header for the graph in the report. The first earthquake was in September 2010 and is marked with red dots.

The figure highlights the earthquake and its major aftershocks using different colors. It is true that we have faced large problems following the 4th September 2010 earthquake and thousands of aftershocks, but can we really make the coroner’s interpretation (already picked up by the media)? In fact, one could have a look at the data before the earthquake, where there are big drops and rises (What would be the explanation for that? Nothing to do with any earthquake). In fact, the average number of suicides hasn’t really changed after the quake.

I typed the data in to this file, calculated the mean number of suicides per month (~6.3) and generated a few random realizations of a Poisson process using that mean; here I’m plotting the real data in panel 1 and 4 other randomly generated series in panels 2 to 5.

Do they really look different? We could try to fit any set of peaks and valleys to our favorite narrative; however, it doesn’t necessarily make any sense. We’ll need a larger data set to see any long-time effects of the earthquake.

What was this about? He read my post on R, Julia and the shiny new thing, which prompted him to assume that I was the proverbial old dog unwilling (or was it unable?) to learn new tricks. (Incidentally, with friends like this who needs enemies? Hi, Gus.)

Having a look at different—statistical—horses (Photo: Luis, click to enlarge).

I decided to tackle a small—but hopefully useful—piece of code: fitting/training a Genome Wide Selection model, using the Bayes A approach put forward by Meuwissen, Hayes and Goddard in 2001. In that approach the breeding values of the individuals (response) are expressed as a function of a very large number of random predictors (2000, our molecular markers). The dataset (csv file) is a simulation of 2000 bi-allelic markers (aa = 0, Aa = 1, AA = 2) for 250 individuals, followed by the phenotypes (column 2001) and breeding values (column 2002). These models are frequently adjusted using MCMC.

In 2010 I attended this course in Ames, Iowa where Rohan Fernando passed us the following R code (pretty much a transliteration from C code; notice the trailing semicolons, for example). P.D. 2012-04-26 Please note that this is teaching code not production code:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

nmarkers=2000;# number of markers

startMarker=1981;# set to 1 to use all

numiter=2000;# number of iterations

vara=1.0/20.0;

# input data

data=matrix(scan("trainData.out0"),ncol=nmarkers+2,byrow=TRUE);

nrecords=dim(data)[1];

beg=Sys.time()

# x has the mean followed by the markers

x=cbind(1,data[,startMarker:nmarkers]);

y=data[,nmarkers+1];

a=data[,nmarkers+2];

# inital values

nmarkers=nmarkers-startMarker+1;

mean2pq=0.5;# just an approximation

scalea=0.5*vara/(nmarkers*mean2pq);# 0.5 = (v-2)/v for v=4

size=dim(x)[2];

b=array(0.0,size);

meanb=b;

b[1]=mean(y);

var=array(0.0,size);

# adjust y

ycorr=y-x%*%b;

# MCMC sampling

for(iter in1:numiter){

# sample vare

vare=(t(ycorr)%*%ycorr)/rchisq(1,nrecords+3);

# sample intercept

ycorr=ycorr+x[,1]*b[1];

rhs=sum(ycorr)/vare;

invLhs=1.0/(nrecords/vare);

mean=rhs*invLhs;

b[1]=rnorm(1,mean,sqrt(invLhs));

ycorr=ycorr-x[,1]*b[1];

meanb[1]=meanb[1]+b[1];

# sample variance for each locus

for(locus in2:size){

var[locus]=(scalea*4+b[locus]*b[locus])/rchisq(1,4.0+1)

}

# sample effect for each locus

for(locus in2:size){

# unadjust y for this locus

ycorr=ycorr+x[,locus]*b[locus];

rhs=t(x[,locus])%*%ycorr/vare;

lhs=t(x[,locus])%*%x[,locus]/vare+1.0/var[locus];

invLhs=1.0/lhs;

mean=invLhs*rhs;

b[locus]=rnorm(1,mean,sqrt(invLhs));

#adjust y for the new value of this locus

ycorr=ycorr-x[,locus]*b[locus];

meanb[locus]=meanb[locus]+b[locus];

}

}

Sys.time()-beg

meanb=meanb/numiter;

aHat=x%*%meanb;

Thus, we just need defining a few variables, reading the data (marker genotypes, breeding values and phenotypic data) into a matrix, creating loops, matrix and vector multiplication and generating random numbers (using a Gaussian and Chi squared distributions). Not much if you think about it, but I didn’t have much time to explore Julia’s features as to go for something more complex.

MATLAB

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

nmarkers=2000#Number of markers

startmarker=1981#Setto1to use all

numiter=2000#Number of iterations

data=dlmread("markers.csv",',')

(nrecords,ncols)=size(data)

tic()

#this isthe meanand markers matrix

X=hcat(ones(Float64,nrecords),data[:,startmarker:nmarkers])

y=data[:,nmarkers+1]

a=data[:,nmarkers+2]

nmarkers=nmarkers-startmarker+1

vara=1.0/nmarkers

mean2pq=0.5

scalea=0.5*vara/(nmarkers*mean2pq)#0.5=(v-2)/vforv=4

ndesign=size(X,2)

b=zeros(Float64,ndesign)

meanb=zeros(Float64,ndesign)

b[1]=mean(y)

varian=zeros(Float64,ndesign)

#adjusty

ycorr=y-X*b

#MCMC sampling

fori=1:numiter

#sample vare

vare=dot(ycorr,ycorr)/randchi2(nrecords+3)

#sample intercept

ycorr=ycorr+X[:,1]*b[1];

rhs=sum(ycorr)/vare;

invlhs=1.0/(nrecords/vare);

mn=rhs*invlhs;

b[1]=randn()*sqrt(invlhs)+mn;

ycorr=ycorr-X[:,1]*b[1];

meanb[1]=meanb[1]+b[1];

#sample variance foreach locus

forlocus=2:ndesign

varian[locus]=(scalea*4+b[locus]*b[locus])/randchi2(4.0+1);

end

#sample effect foreach locus

forlocus=2:ndesign

#unadjustyforthis locus

ycorr=ycorr+X[:,locus]*b[locus];

rhs=dot(X[:,locus],ycorr)/vare;

lhs=dot(X[:,locus],X[:,locus])/vare+1.0/varian[locus];

invlhs=1.0/lhs;

mn=invlhs*rhs;

b[locus]=randn()*sqrt(invlhs)+mn;

#adjustyforthe new value of this locus

ycorr=ycorr-X[:,locus]*b[locus];

meanb[locus]=meanb[locus]+b[locus];

end

end

toc()

meanb=meanb/numiter;

aHat=X*meanb;

The code looks remarkably similar and there are four main sources of differences:

The first trivial one is that the original code read a binary dataset and I didn’t know how to do it in Julia, so I’ve read a csv file instead (this is why I start timing after reading the file too).

The second trivial one is to avoid name conflicts between variables and functions; for example, in R the user is allowed to have a variable called var that will not interfere with the variance function. Julia is picky about that, so I needed renaming some variables.

Julia pases variables by reference, while R does so by value when assigning matrices, which tripped me because in the original R code there was something like: b = array(0.0,size); meanb = b;. This works fine in R, but in Julia changes to the b vector also changed meanb.

The definition of scalar vs array created some problems in Julia. For example y' * y (t(y) %*% y in R) is numerically equivalent to dot(y, y). However, the first version returns an array, while the second one a scalar. I got an error message when trying to store the ‘scalar like an array’ in to an array. I find that confusing.

One interesting point in this comparison is using rough code, not really optimized for speed; in fact, the only thing that I can say of the Julia code is that ‘it runs’ and it probably is not very idiomatic. Testing runs with different numbers of markers we get that R needs roughly 2.8x the time used by Julia. The Julia website claims better results in benchmarks, but in real life we work with, well, real problems.

In 1996-7 I switched from SAS to ASReml for genetic analyses because it was 1-2 orders of magnitude faster and opened a world of new models. Today a change from R to Julia would deliver (in this particular case) a much more modest speed up (~3x), which is OK but not worth changing languages (yet). Together with the embryonic graphical capabilities and the still-to-develop ecosystem of packages, means that I’m still using R. Nevertheless, the Julia team has achieved very impressive performance in very little time, so it is worth to keep an eye on their progress.

P.S.1 Readers are welcome to suggesting ways of improving the code.
P.S.2 WordPress does not let me upload the binary version of the simulated data.
P.S.3 Hey WordPress guys; it would be handy if the sourcecode plugin supported Julia!
P.S.4 2012-04-26 Following AL’s recommendation in the comments, one can replace in R:

1

2

rhs=t(x[,locus])%*%ycorr/vare;

lhs=t(x[,locus])%*%x[,locus]/vare+1.0/var[locus]

by

1

2

rhs=crossprod(x[,locus],ycorr)/vare

lhs=crossprod(x[,locus],x[,locus])/vare+1.0/var[locus]

reducing execution time by roughly 20%, making the difference between Julia and R even smaller.

Every year there is at least a couple of occasions when I have to simulate multivariate data that follow a given covariance matrix. For example, let’s say that we want to create an example of the effect of collinearity when fitting multiple linear regressions, so we want to create one variable (the response) that is correlated with a number of explanatory variables and the explanatory variables have different correlations with each other.

There is a matrix operation called Cholesky decomposition, sort of equivalent to taking a square root with scalars, that is useful to produce correlated data. If we have a covariance matrix M, the Cholesky descomposition is a lower triangular matrix L, such as that M = L L'. How does this connect to our simulated data? Let’s assume that we generate a vector z of random normally independently distributed numbers with mean zero and variance one (with length equal to the dimension of M), we can create a realization of our multivariate distribution using the product L z.

The reason why this works is that the Variance(L z) = L Variance(z) L' as L is just a constant. The variance of z is the identity matrix I; remember that the random numbers have variance one and are independently distributed. Therefore Variance(L z) = L I L' = L L` = M so, in fact, we are producing random data that follow the desired covariance matrix.

As an example, let’s simulate 100 observations with 4 variables. Because we want to simulate 100 realizations, rather than a single one, it pays to generate a matrix of random numbers with as many rows as variables to simulate and as many columns as observations to simulate.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

library(lattice)# for splom

library(car)# for vif

# number of observations to simulate

nobs=100

# Using a correlation matrix (let' assume that all variables

# have unit variance

M=matrix(c(1,0.7,0.7,0.5,

0.7,1,0.95,0.3,

0.7,0.95,1,0.3,

0.5,0.3,0.3,1),nrow=4,ncol=4)

# Cholesky decomposition

L=chol(M)

nvars=dim(L)[1]

# R chol function produces an upper triangular version of L

# so we have to transpose it.

# Just to be sure we can have a look at t(L) and the

# product of the Cholesky decomposition by itself

t(L)

[,1][,2][,3][,4]

[1,]1.00.00000000.000000000.0000000

[2,]0.70.71414280.000000000.0000000

[3,]0.70.64412880.308379700.0000000

[4,]0.5-0.0700140-0.015895860.8630442

t(L)%*%L

[,1][,2][,3][,4]

[1,]1.00.700.700.5

[2,]0.71.000.950.3

[3,]0.70.951.000.3

[4,]0.50.300.301.0

# Random variables that follow an M correlation matrix

r=t(L)%*%matrix(rnorm(nvars*nobs),nrow=nvars,ncol=nobs)

r=t(r)

rdata=as.data.frame(r)

names(rdata)=c('resp','pred1','pred2','pred3')

# Plotting and basic stats

splom(rdata)

cor(rdata)

# We are not that far from what we want to simulate!

resp pred1 pred2 pred3

resp1.00000000.73475720.75168080.3915817

pred10.73475721.00000000.95873860.2841598

pred20.75168080.95873861.00000000.2942844

pred30.39158170.28415980.29428441.0000000

Now we can use the simulated data to learn something about the effects of collinearity when fitting multiple linear regressions. We will first fit two models using two predictors with low correlation between them, and then fit a third model with three predictors where pred1 and pred2 are highly correlated with each other.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

# Model 1: predictors 1 and 3 (correlation is 0.28)

m1=lm(resp~pred1+pred3,rdata)

summary(m1)

Coefficients:

Estimate Std.Errortvalue Pr(>|t|)

(Intercept)0.075360.068121.1060.27133

pred10.673160.068429.8382.99e-16***

pred30.209200.072532.8840.00483**

---

Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residual standard error:0.6809on97degrees of freedom

MultipleR-squared:0.5762,AdjustedR-squared:0.5675

F-statistic:65.95on2and97DF,p-value:<2.2e-16

# Model 2: predictors 2 and 3 (correlation is 0.29)

m2=lm(resp~pred2+pred3,rdata)

summary(m2)

Coefficients:

Estimate Std.Errortvalue Pr(>|t|)

(Intercept)0.061210.066490.9210.35953

pred20.685130.0663310.329<2e-16***

pred30.196240.070972.7650.00681**

---

Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residual standard error:0.6641on97degrees of freedom

MultipleR-squared:0.5968,AdjustedR-squared:0.5885

F-statistic:71.79on2and97DF,p-value:<2.2e-16

# Model 3: correlation between predictors 1 and 2 is 0.96

m3=lm(resp~pred1+pred2+pred3,rdata)

summary(m3)

Coefficients:

Estimate Std.Errortvalue Pr(>|t|)

(Intercept)0.064210.066760.9620.33856

pred10.168440.225600.7470.45712

pred20.525250.224222.3430.02122*

pred30.195840.071142.7530.00706**

---

Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residual standard error:0.6657on96degrees of freedom

MultipleR-squared:0.5991,AdjustedR-squared:0.5866

F-statistic:47.83on3and96DF,p-value:<2.2e-16

# Variance inflation

vif(m3)

pred1 pred2 pred3

12.37382612.4531651.094875

In my example it is possible to see the huge increase for the standard error for pred1 and pred2, when we use both highly correlated explanatory variables in model 3. In addition, model fit does not improve for model 3.