r - Simulate array with scatter & known relation to X -
this basic r question, can't seem find right packages want.
i have array 'x', n values. want simulate array, 'y', follows known relation y = alpha + beta*x. furthermore, want add intrinsic scatter y array. alpha, beta, , intrinsic scatter should input values user.
can me how go doing this?
thanks!
here function creates deterministic part of correlation , adds noise via rnorm
make_correlation <- function(alpha, beta, scatter, x){ # make deterministic part y_det <- alpha + beta*x # add noise y <- rnorm(length(x), y_det, scatter) return(y) } set.seed(20) x <- runif(20, 0, 10) answer <- make_correlation(alpha = 2, beta = 3, scatter = 2, x)
plot(answer~x)
Comments
Post a Comment