regr.est <- function(x, y, mux, N = NA) { # regression estimator of a population mean and total. # x is auxiliary variable, y is response, mux is population mean # of x, N is population size (assumed # infinite if no value given), if(length(x) != length(y)) stop("x and y must be same length") n <- length(x) fpc <- 1 if(!is.na(N)) fpc <- (N - n)/N ab <- lsfit(x, y) cat("mu-hat=", ab$coef[1] + ab$coef[2] * mux, " SE=", sqrt((fpc * sum(ab$residual^2))/(n * (n -2))), "\n") if(!is.na(N)) cat("tau-hat=", N*(ab$coef[1] + ab$coef[2] * mux), " SE=", N*sqrt((fpc * sum(ab$residual^2))/(n * (n -2))), "\n") }