R/mregnn.R

## z = Xb unrestricted
mregnn <- function (x, y, a) {
  k <- qr.Q(qr(x))
  u <- drop (crossprod(k, y))
  v <- -crossprod (k, t(a))
  lb <- nnls(v, u)$x
  xb <- drop(k %*% (u - v %*% lb))
  return (list(xb = xb, lb = lb, f = sum((y - xb) ^ 2)))
}

## z monotone restricted
mregnnM <- function (x, y) {
  k <- qr.Q(qr(x))
  u <- drop (crossprod(k, y))
  v <- -t(diff(k))
  lb <- nnls(v, u)$x
  xb <- drop(k %*% (u - v%*% lb))
  return (list(xb = xb, lb = lb, f = sum((y - xb) ^ 2)))
}

## z positive
mregnnP <- function (x, y) {
  k <- qr.Q(qr(x))
  u <- drop (crossprod(k, y))
  v <- -t(k)
  lb <- nnls(v, u)$x
  xb <- drop(k %*% (u - v%*% lb))
  return (list(xb = xb,lb = lb, f = sum((y - xb) ^ 2)))
}

Try the isotone package in your browser

Any scripts or data that you put into this service are public.

isotone documentation built on March 7, 2023, 6:58 p.m.