regression {RGeostats}R Documentation

Linear Regression

Description

Linear Regression

Usage

regression(db, name1=db.getname(db,"z",1), names=NA, db2=NA, uc=c("1"),
           flag.mode=0, flag.one=TRUE, verbose = 0, save.coeff = FALSE, 
           flag.draw=FALSE, ...)

Arguments

db

The db-class containing the data information used to calculate the linear regression of the target variable.

name1

Rank of the target variable in the Db for which a linear multivariate regression must be established.

names

List of names of attributes that are used as explanatory variables. For more information see db.ident.

db2

If 'db2' is specified, the explanatory variables are read from this Db. This Db2 must have exactly the same organization as 'Db'. If not defined, 'db2' is replaced by 'db1'.

uc

The drift description. Use command uc.names for details.

flag.mode
  • 0: the regression is calculated for variable 'name1' (from 'db') as a function of variables specified by 'names' (from 'db2')

  • 1: the regression is calculated for variable Z (from 'db') as a function of the whole set of Fi variables (from 'db2')

  • 2: the regression is calculated for the variable Z (from 'db') as a function of the drift monomials as specified in the argument 'uc' (from 'db2')

flag.one

When TRUE, the constant is considered as an additional explanatory variable. This only makes sense for flag.mode equal to 0 or 1; in the case of flag.mode==2, the constant may be directly specified in the 'uc' argument.

verbose
  • 0 No printout

  • 1 for the printout of the regression equation

  • 2 for the printout of the equation as wells as the pointwise residuals

save.coeff

Defines the output option:

  • FALSE : the returned argument is a db-class where the regression residuals have been added.

  • TRUE : the returned argument is a list containing the count of active data, the coefficients of the linear regression, the variance of the active data, the variance of residuals and the correlation coefficient.

flag.draw

When TRUE (and if 'mode' is 0 and a graphic already exists), the regression line is overlaid on the current figure.

...

Parameters passed to the function lines.

Value

The returned value depends upon the argument save.coeff.

Examples

# Load the information from the Scotland 2-D Data Set (renamed as db)
# The Db contains 236 samples with variables "Elevation" and "January_temp".
data(Exdemo_Scotland_Temperatures)
db = Exdemo_Scotland_Temperatures

###########################
# flag.mode = 0 (default) #
###########################
# Perform the linear regression of the variable (y) 'Elevation' as a
# function of explanatory variable (x) 'January_temp' with a constant
regression(db,"Elevation","January_temp",flag.one=TRUE,save.coeff=TRUE)
# The resulting equation is: y = 287.87 - x * 71.022

# Perform the same regression with no ordinate at the origin
regression(db,"Elevation","January_temp",flag.one=FALSE,save.coeff=TRUE)
# The resulting equation is: y = 19.59 * x

#################
# flag.mode = 1 #
#################
# We consider the variable "January_temp" as an external drift
db = db.locate(db,"January_temp","f")
# Perform the regression of the first data variable (locator "z1")
# as a function of the external drift(s)
regression(db,flag.mode=1,save.coeff=TRUE)
# The resulting equation is (again): y = 287.87 - x * 71.022

#################
# flag.mode = 2 #
#################
# We use the standard drift definition in the regression
regression(db,flag.mode=2,uc=c("1","f1"),save.coeff=TRUE)
# The resulting equation is (again): y = 287.87 * x - 71.022

# In order to suppress the ordinate at the origin, we must run:
regression(db,flag.mode=2,uc=c("f1"),save.coeff=TRUE)
# The resulting equation is (again): y = 19.59 * x

# The next test is to perform the regression of the main variable as a
# function of a complex drift composed of a constant, the external
# drift, the first order coordinates
regression(db,flag.mode=2,uc=c("1","f1","x","y"),save.coeff=TRUE)
# The resulting equation is:
# y = 401.69 - 77.84 * f1 - 0.2178 * x1 - 0.0425 * x2

[Package RGeostats version 14.0.10 Index]