invreg3 <- function(x,delta) {
# this function takes two inputs: x and delta, and returns one vector, b.
# It is an implementation of Duan and Li (1991) inverse regression.
#
# Inputs: x is a matrix of N rows, the design matrix.
# delta is a vector of length N, consist of H (>1) different values:
# d1