g <- function(x){ exp(-.5*(x^2))+.5*exp(-.5*((x-3)^2)) } vals <- rt(10000,df=1) w <- g(vals)/dt(vals,df=1) q <- w/sum(w) out <- sample(vals,size=3002,replace=T,prob=q) mean(out) sqrt(var(out)) mean((out<0)) xx<-seq(-3,6,length=100) hist(out,nclass=50,prob=T,xlab="") lines(density(out),lwd=4,col="blue") lines(xx,.67*dnorm(xx,0,1)+.33*dnorm(xx,3,1),lwd=4,col="red")