For example, I would like two variables,
y to have a correlation coefficient of 0.7 and a slope of 1.5, with a specified mean and sample size for both variables. I don't care if the data is normal or not.
I messed around with
MASS a lot, using
mvrnorm to get a specific correlation coefficient, but I couldn't manipulate it to also give me the slope.
out <- mvrnorm(100, mu = c(0,0), Sigma = matrix(c(1,.5,.5,1),ncol = 2), empirical = TRUE)
This gives me a correlation coefficient of 0.5, but it also gives me a slope of 0.5 when I plot the data.
cor(out) plot(out) cor(out[,1], out[,2]) fit <- lm(out[,2]~out[,1]) fit # Call: # lm(formula = out[, 2] ~ out[, 1]) # Coefficients: # (Intercept) out[, 1] # -8.604e-17 5.000e-01
Is there a program that can do what I want or anyway to get these requirement on point by hand?