ratio.est <- function(x, y, mux = NA, N = NA) { # estimate of a ratio and ratio estimate of population mean and total. # x is auxiliary variable, y is response, mux is population mean # of x (xbar is used if no value is given), # 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 r <- sum(y)/sum(x) sr2 <- (1/(n - 1)) * sum((y - r * x)^2) if(is.na(mux)) mx <- mean(x) else mx <- mux cat("r=", r, " SE=", sqrt((fpc * sr2)/(mx^2 * n)), "\n") if(!is.na(mux)) cat("mu-hat=", r * mux, " SE=", sqrt((fpc * sr2)/n), "\n") if(!is.na(N) & !is.na(mux)) cat("tau-hat=", N*r * mux, " SE=", N*sqrt((fpc * sr2)/n), "\n") }