How to generated skewed distribution with specific means and variances (in R)? For teaching purposes I'm trying to generate some probability distributions that have varying amounts of skew but precisely controllable mean and variance. I'd like to plot these distributions and also sample from them.
The skew-normal distribution and its R implementation almost fit the bill except that the skew, mean, and variance parameters can't be controlled independently. Changing the skew also changes the mean and variance. For example
library(sn)
x <- seq(-4, 4, by = .01)
y <- dsn(x, xi = 0, omega = 1, alpha=4)
plot(x,y)


here you can see that modifying the skew-related parameter (alpha) also changed the mean of the distribution to a positive value.
I'd like to be able to modify the skew while keeping the mean at 0 and the variance at 1, or while holding the mean and variance at other specified values.
Any advice on how to do this?


except that the skew, mean, and variance parameters can't be controlled independently

Not true :-). With the function cp2dp of the sn package, you can convert from the population mean, the population standard deviation and the population skewness to the parameters xi, omega and alpha of the skew-normal distribution.
library(sn)
params <- cp2dp(c(5, 2, -0.5), "SN")
params
#        xi     omega     alpha 
#  7.104419  2.903201 -2.173758 

set.seed(666L)
sims <- rsn(5000L, dp = params)
mean(sims) # approx 5
sd(sims) # approx 2

x <- seq(-2, 10, length.out = 500)
y <- dsn(x, dp = params)
plot(x, y, type = "l")


Note that the SN family only supports skewness between -0.99527 and 0.99527. Outside of this range, the ST family is needed, which requires a fourth parameter: the kurtosis.
