MR: Multiple regression

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/MR.r

Description

Functions for reconstructing (predicting) environmental values from biological assemblages using multiple regression.

Usage

 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
MR(y, x, check.data=TRUE, lean=FALSE, ...)

MR.fit(y, x, lean=FALSE)

## S3 method for class 'MR'
 predict(object, newdata=NULL, sse=FALSE, nboot=100,
      match.data=TRUE, verbose=TRUE, ...)

## S3 method for class 'MR'
crossval(object, cv.method="loo", verbose=TRUE, ngroups=10,
      nboot=100, h.cutoff=0, h.dist=NULL, ...)

## S3 method for class 'MR'
performance(object, ...)

## S3 method for class 'MR'
print(x, ...)

## S3 method for class 'MR'
summary(object, full=FALSE, ...)

## S3 method for class 'MR'
plot(x, resid=FALSE, xval=FALSE, xlab="", 
      ylab="", ylim=NULL, xlim=NULL, add.ref=TRUE,
      add.smooth=FALSE, ...)

## S3 method for class 'MR'
residuals(object, cv=FALSE, ...)

## S3 method for class 'MR'
coef(object, ...)

## S3 method for class 'MR'
fitted(object, ...)

Arguments

y

a data frame or matrix of biological abundance data.

x, object

a vector of environmental values to be modelled or an object of class wa.

newdata

new biological data to be predicted.

check.data

logical to perform simple checks on the input data.

match.data

logical indicate the function will match two species datasets by their column names. You should only set this to FALSE if you are sure the column names match exactly.

lean

logical to exclude some output from the resulting models (used when cross-validating to speed calculations).

full

logical to show head and tail of output in summaries.

resid

logical to plot residuals instead of fitted values.

xval

logical to plot cross-validation estimates.

xlab, ylab, xlim, ylim

additional graphical arguments to plot.wa.

add.ref

add 1:1 line on plot.

add.smooth

add loess smooth to plot.

cv.method

cross-validation method, either "loo", "lgo", "bootstrap" or "h-block".

verbose

logical to show feedback during cross-validation.

nboot

number of bootstrap samples.

ngroups

number of groups in leave-group-out cross-validation, or a vector contain leave-out group menbership.

h.cutoff

cutoff for h-block cross-validation. Only training samples greater than h.cutoff from each test sample will be used.

h.dist

distance matrix for use in h-block cross-validation. Usually a matrix of geographical distances between samples.

sse

logical indicating that sample specific errors should be calculated.

cv

logical to indicate model or cross-validation residuals.

...

additional arguments.

Details

Function MR performs multiple regrssion. It is a wrapper to lm.

Function predict predicts values of the environmental variable for newdata or returns the fitted (predicted) values from the original modern dataset if newdata is NULL. Variables are matched between training and newdata by column name (if match.data is TRUE). Use compare.datasets to assess conformity of two species datasets and identify possible no-analogue samples.

MR has methods fitted and rediduals that return the fitted values (estimates) and residuals for the training set, performance, which returns summary performance statistics (see below), coef which returns the species coefficients, and print and summary to summarise the output. MR also has a plot method that produces scatter plots of predicted vs observed measurements for the training set.

Value

Function MR returns an object of class MR with the following named elements:

coefficients

species coefficients (the updated "optima").

fitted.values

fitted values for the training set.

call

original function call.

x

environmental variable used in the model.

Function crossval also returns an object of class MR and adds the following named elements:

predicted

predicted values of each training set sample under cross-validation.

residuals.cv

prediction residuals.

If function predict is called with newdata=NULL it returns the fitted values of the original model, otherwise it returns a list with the following named elements:

fit

predicted values for newdata.

If sample specific errors were requested the list will also include:

fit.boot

mean of the bootstrap estimates of newdata.

v1

standard error of the bootstrap estimates for each new sample.

v2

root mean squared error for the training set samples, across all bootstram samples.

SEP

standard error of prediction, calculated as the square root of v1^2 + v2^2.

Function performance returns a matrix of performance statistics for the MR model. See performance, for a description of the summary.

Author(s)

Steve Juggins

See Also

WA, MAT, performance, and compare.datasets for diagnostics.

Examples

 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
data(IK)
spec <- IK$spec
SumSST <- IK$env$SumSST
core <- IK$core

# Generate a MR model using taxa with max abun > 20%

mx <- apply(spec, 2, max)
spec2 <- spec[, mx > 20]

fit <- MR(spec2, SumSST)
fit
# cross-validate model
fit.cv <- crossval(fit, cv.method="lgo")
fit.cv

#predict the core
pred <- predict(fit, core)

#plot predictions - depths are in rownames
depth <- as.numeric(rownames(core))
plot(depth, pred$fit[, 1], type="b")

## Not run: 
# predictions with sample specific errors
# takes approximately 1 minute to run
pred <- predict(fit, core, sse=TRUE, nboot=1000)
pred

## End(Not run)

Example output

This is rioja 0.9-26

Method : Multiple regression
Call   : MR(y = spec2, x = SumSST) 

No. samples        : 61 
No. species        : 7 
Cross val.         : none 


Performance:
        RMSE     R2  Avg.Bias  Max.Bias   Skill
xHat  1.7332  0.939         0    4.3078  93.904

Cross-validating:

  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |======================================================================| 100%

Method : Multiple regression
Call   : MR(y = spec2, x = SumSST) 

No. samples        : 61 
No. species        : 7 
Cross val.         : lgo : no. groups =  10 


Performance:
             RMSE      R2  Avg.Bias  Max.Bias    Skill
xHat       1.7332  0.9390    0.0000    4.3078  93.9040
xHat_XVal  2.1507  0.9075    0.0817    6.4138  90.6131

Bootstrapping for SSE:

  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |                                                                      |   1%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |==                                                                    |   4%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   6%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |=======                                                               |  11%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |=========                                                             |  14%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |==============                                                        |  19%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |==============                                                        |  21%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |================                                                      |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |================                                                      |  24%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |=================                                                     |  25%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |==================                                                    |  26%
  |                                                                            
  |===================                                                   |  26%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |===================                                                   |  28%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |=====================                                                 |  31%
  |                                                                            
  |======================                                                |  31%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  32%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |=======================                                               |  34%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |=========================                                             |  35%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |===========================                                           |  39%
  |                                                                            
  |============================                                          |  39%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |============================                                          |  41%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |==============================                                        |  44%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  46%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |===================================                                   |  49%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |===================================                                   |  51%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |=====================================                                 |  52%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |=====================================                                 |  54%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |========================================                              |  58%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  59%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |==========================================                            |  61%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |============================================                          |  64%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |=============================================                         |  65%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  66%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |===============================================                       |  68%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |=================================================                     |  71%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |===================================================                   |  74%
  |                                                                            
  |====================================================                  |  74%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=====================================================                 |  75%
  |                                                                            
  |=====================================================                 |  76%
  |                                                                            
  |======================================================                |  76%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |======================================================                |  78%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |========================================================              |  79%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |========================================================              |  81%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==========================================================            |  82%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |==========================================================            |  84%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |===========================================================           |  85%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  86%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===============================================================       |  89%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |===============================================================       |  91%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |=================================================================     |  94%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  95%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |====================================================================  |  98%
  |                                                                            
  |===================================================================== |  98%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================|  99%
  |                                                                            
  |======================================================================| 100%
$fit
         xHat
0    26.71122
10   26.64619
20   26.57309
30   26.45048
40   26.16588
50   26.38003
60   25.72367
70   26.19773
80   26.62691
90   25.43421
100  26.50853
110  24.85337
120  25.69105
130  25.50769
140  25.20482
150  26.05907
160  26.20813
170  26.30850
180  25.72480
190  26.68484
200  26.48232
210  27.15822
220  26.92482
230  26.80370
240  27.45008
250  26.00850
260  26.48246
270  26.28820
280  26.14246
290  25.98937
300  26.54410
310  25.66524
320  25.98580
330  24.92261
340  26.40838
350  26.61968
360  26.25345
370  27.43525
380  27.34519
390  26.84034
400  25.95012
410  27.71027
420  27.11003
430  27.03440
440  26.63537
450  27.19424
460  27.14265
470  26.47249
480  25.82700
490  27.37246
500  27.36792
510  26.34557
520  26.12214
530  26.22765
540  25.78979
550  24.30946
560  24.64812
570  25.20117
580  24.76029
590  27.28018
600  26.38642
610  26.26184
620  26.68613
630  25.26546
640  26.44084
650  26.23448
660  26.64549
670  24.60048
680  26.35641
690  27.71286
700  26.51855
710  27.63652
720  26.79966
730  26.74068
740  26.33218
750  26.12681
760  26.80972
770  27.78221
780  28.00992
790  27.47895
800  27.51082
810  26.69522
820  25.37752
830  25.86032
840  26.33881
850  26.65550
860  26.22674
870  27.10797
880  25.75509
890  23.67379
900  24.32739
910  24.35191
920  25.74931
930  26.62692
940  26.82857
950  25.74873
960  25.92590
970  26.47843
980  25.69170
990  25.50108
1000 25.56994
1010 23.50508
1020 23.32175
1030 23.34593
1040 24.36962
1050 25.51290
1060 24.82823
1070 24.65616
1080 25.72838
1090 25.52457

$fit.boot
         xHat
0    26.76906
10   26.74446
20   26.60033
30   26.44379
40   26.19010
50   26.32765
60   25.68135
70   26.22089
80   26.60174
90   25.49814
100  26.51613
110  24.96943
120  25.68321
130  25.53385
140  25.24550
150  26.08352
160  26.23693
170  26.31981
180  25.86054
190  26.77626
200  26.60436
210  27.21762
220  27.05026
230  26.91872
240  27.56844
250  26.12647
260  26.62446
270  26.49781
280  26.28925
290  26.16111
300  26.60868
310  25.78909
320  25.99764
330  25.02463
340  26.42719
350  26.72055
360  26.28714
370  27.46089
380  27.41846
390  26.84428
400  25.96817
410  27.74162
420  27.14467
430  27.06714
440  26.68614
450  27.32232
460  27.26900
470  26.52111
480  25.80084
490  27.47484
500  27.40225
510  26.49049
520  26.15302
530  26.11338
540  25.64463
550  24.35179
560  24.75131
570  25.25542
580  24.85702
590  27.25419
600  26.50359
610  26.38470
620  26.80201
630  25.41939
640  26.59298
650  26.37395
660  26.69010
670  24.65318
680  26.42718
690  27.72868
700  26.58800
710  27.67482
720  26.85996
730  26.85349
740  26.44488
750  26.26077
760  26.89466
770  27.75641
780  28.12080
790  27.57989
800  27.60459
810  26.82076
820  25.54045
830  25.93970
840  26.36943
850  26.74196
860  26.24362
870  27.03184
880  25.79843
890  23.68582
900  24.26858
910  24.32857
920  25.70664
930  26.69724
940  26.87298
950  25.91562
960  25.96754
970  26.47116
980  25.73437
990  25.62062
1000 25.67876
1010 23.69345
1020 23.33462
1030 23.43994
1040 24.34906
1050 25.57639
1060 24.89399
1070 24.67280
1080 25.83389
1090 25.60704

$v1.boot
          xHat
0    0.3569620
10   0.4851095
20   0.2865209
30   0.2599749
40   0.3049859
50   0.4008983
60   0.6264100
70   0.2647051
80   0.2948312
90   0.3937107
100  0.2664151
110  0.5374075
120  0.4477890
130  0.3561528
140  0.5059011
150  0.2984120
160  0.2068106
170  0.4406386
180  0.6466722
190  0.3941188
200  0.4939613
210  0.4409234
220  0.5192128
230  0.4151763
240  0.6382401
250  0.4572604
260  0.5426363
270  0.7703451
280  0.5358275
290  0.5856931
300  0.3159743
310  0.4772523
320  0.2362658
330  0.4991153
340  0.2800132
350  0.3823540
360  0.3792662
370  0.4058485
380  0.5154404
390  0.3456421
400  0.5501446
410  0.5998183
420  0.3005966
430  0.3697616
440  0.4313454
450  0.5582725
460  0.4912292
470  0.2292218
480  0.4793080
490  0.6062410
500  0.4839634
510  0.6087014
520  0.4911547
530  0.4380335
540  0.6289290
550  0.4305486
560  0.5786207
570  0.4015105
580  0.4040703
590  0.2740861
600  0.5921934
610  0.6866960
620  0.6785999
630  0.5354561
640  0.5257536
650  0.4605614
660  0.3539234
670  0.3188508
680  0.6879629
690  0.4910126
700  0.3593976
710  0.5327060
720  0.6550022
730  0.7398646
740  0.4900520
750  0.5467623
760  0.4335327
770  0.5158664
780  0.8291651
790  0.5164289
800  0.5022918
810  0.4828299
820  0.6405184
830  0.3890775
840  0.4713782
850  0.5998234
860  0.5582944
870  0.4995044
880  0.3238626
890  0.4922305
900  0.5240311
910  0.5365026
920  0.4733349
930  0.4910287
940  0.3005784
950  0.6156369
960  0.3007403
970  0.2657781
980  0.3333714
990  0.5026560
1000 0.4447187
1010 0.9072392
1020 0.5073203
1030 0.4933763
1040 0.8800484
1050 0.3267854
1060 0.5645879
1070 0.2607544
1080 0.4426554
1090 0.3125804

$v2.boot
[1] 2.102188

$SEP.boot
         xHat
0    2.132280
10   2.157435
20   2.121624
30   2.118203
40   2.124197
50   2.140073
60   2.193532
70   2.118788
80   2.122762
90   2.138739
100  2.119003
110  2.169793
120  2.149351
130  2.132144
140  2.162205
150  2.123263
160  2.112337
170  2.147873
180  2.199404
190  2.138814
200  2.159443
210  2.147931
220  2.165358
230  2.142794
240  2.196940
250  2.151344
260  2.171094
270  2.238890
280  2.169402
290  2.182254
300  2.125802
310  2.155682
320  2.115423
330  2.160627
340  2.120755
350  2.136677
360  2.136127
370  2.141006
380  2.164457
390  2.130414
400  2.172983
410  2.186087
420  2.123571
430  2.134460
440  2.145986
450  2.175055
460  2.158819
470  2.114648
480  2.156138
490  2.187858
500  2.157178
510  2.188541
520  2.158802
530  2.147340
540  2.194253
550  2.145826
560  2.180366
570  2.140188
580  2.140670
590  2.119981
600  2.184007
610  2.211503
620  2.209003
630  2.169311
640  2.166936
650  2.152048
660  2.131773
670  2.126232
680  2.211897
690  2.158770
700  2.132689
710  2.168633
720  2.201868
730  2.228586
740  2.158552
750  2.172129
760  2.146426
770  2.164558
780  2.259803
790  2.164693
800  2.161363
810  2.156924
820  2.197603
830  2.137891
840  2.154389
850  2.186089
860  2.175060
870  2.160717
880  2.126989
890  2.159047
900  2.166519
910  2.169569
920  2.154818
930  2.158774
940  2.123568
950  2.190480
960  2.123591
970  2.118923
980  2.128458
990  2.161448
1000 2.148714
1010 2.289602
1020 2.162538
1030 2.159309
1040 2.278965
1050 2.127436
1060 2.176684
1070 2.118298
1080 2.148287
1090 2.125300

rioja documentation built on Oct. 28, 2020, 5:07 p.m.

Related to MR in rioja...