# faker(n, mu, sd) # Generate n>1 samples with prescribed mean mu and standard deviation sd # M.V.Wickerhauser, 30 Jan 2016 # # Method: # Let y_i = mu - a, if i=1,2,...,n-1, # mu+(n-1)a, if i=n # # Then the mean of {y_1,...,y_n} is exactly mu, # and the variance is # sd^2 = (n-1)^{-1} sum (y_i-mu)^2 = n*a^2, # so let a=sd/sqrt(n). # # faker <- function(n=2, mu=0, sd=1) { if(n<2) stop("Must specify n>1"); if(sd<0) warning("Should have sd>0. Using abs(sd)"); a <- sqrt(sd*sd/n); y <- c( rep(mu-a, n-1 ), mu+(n-1)*a ); return(y); }