mlsreg {lazy.stat}R Documentation

Monotone Least Squares Regression of y on x

Description

Optimal Scaling of y according to x or Isotonic Regression of y on x.
Find yhat which minimizes
rss = sum( w * (y - yhat(x))^2 )
subject to that the order of yhat(x) is equal to that of x,
where w is the observation weight.

Usage

mlsreg(
  y,
  x = 1:min(length(y), nrow(y)),
  w = 1,
  method = 4,
  plot = 0,
  print = 0,
  colvec = 0,
  outG = 0
)

Arguments

y

criterion variable

x

regressor variable in nominal, ordinal, or interval scale.

w

optional weight vector

method

= 1 when x is continuous nominal
= 2 when x is discrete nominal (Fisher)
= 3 when x is continuous ordinal (SAS opscal with untie)
= 4 when x is discrete ordinal (SAS opscal or R isoreg)
= 5 when x is interval (linear regression of y on x)
= 6 when x is ratio (linear regression of y on x w/o intercept)

plot

= 1 to plot the result.

print

= 1 to print the result.

colvec

= 1 to make the result a column vector.

outG

= 1 to return the design matrix when method <= 4.

Details

This program finds yhat(x) which minimizes:
rss = sum( w * (y - yhat(x))^2 )
where yhat(x) is the optimal transformation of x
under the scale level assumption specified by method.

method = 4 is equivalent to R's isoreg function.

Note that, yhat can be calculated as
yhat=G%*%solve(t(G)%*%(w*G))%*%t(G)%*%(w*y)
if we know which observations are to be averaged.

For regressing binary criterion variable (freq,n) on x, use mbinreg.

Value

yhat The fitted value as a function of x.
G The design matrix to calculate yhat as yhat=G%*%solve(t(G)%*%(w*G))%*%t(G)%*%(w*y) when outG=1 and method <= 4.

References

Kruskal, J. B. (1964) Nonmetric multidimensional scaling: A numerical method. Psychometrika, vol. 29. pp115-129.

de Leeuw, J. (1977) Correctness of Kruskal's algorithm for monotone regression with ties. Psychometrika, vol. 42. pp141-144.

Examples

set.seed(1701)
n <- 20
x <- floor(10*runif(n))
y <- 10*runif(n)+1.5*x
yhat1 <- mlsreg( y,x, method=1, print=1, plot=1 )
yhat2 <- mlsreg( y,x, method=2, print=1, plot=1 )
yhat3 <- mlsreg( y,x, method=3, print=1, plot=1 )
yhat4 <- mlsreg( y,x, method=4, print=1, plot=1 )
yhat5 <- mlsreg( y,x, method=5, print=1, plot=1 )
yhat6 <- mlsreg( y,x, method=6, print=1, plot=1 )

# weighted monotone regression
w <- rep(c(1,9),n/2)
yhat33 <- mlsreg( y,x, w, method=3, print=1 )
yhat44 <- mlsreg( y,x, w, method=4, print=1 )
yhat55 <- mlsreg( y,x, w, method=5, print=1 )

# yhat from G matrix
res <- mlsreg( y,x, method=4, print=1, outG=1 )
yhat <- res$yhat
G <- res$G
yfromG <- G%*%solve(t(G)%*%G)%*%t(G)%*%y
Print(yhat,yfromG, yhat-yfromG)

# monotone spline
res <- spreg( y,x, type="m", nknots=2, plot=1, print=1 )


[Package lazy.stat version 0.1.4 Index]