Re: [R] How to programme R to randomly replace some X values with Outliers

2010-10-03 Thread Michael Bedward
N <- 100 Nrep <- 5 X <- runif(N, 0, 10) Y <- 6 + 2*X + rnorm(N, 0, 1) X[ sample(which(Y < 15), Nrep) ] <- runif(Nrep, 15, 20) Hope this helps, Michael On 3 October 2010 16:12, Hock Ann Lim wrote: > Dear experts, > I am a beginner of R. > I'm looking for experts to guide me how to do programmin

Re: [R] How to programme R to randomly replace some X values with Outliers

2010-10-03 Thread Joshua Wiley
Dear Hock Ann, I am not sure of all your requirements, but this should at least get you started. I show it by hand and also wrapped up in a function. In the function I made two density plots that I thought might be interesting to you, you can just delete those two lines of code if you do not wan

[R] How to programme R to randomly replace some X values with Outliers

2010-10-02 Thread Hock Ann Lim
Dear experts, I am a beginner of R. I'm looking for experts to guide me how to do programming in R in order to randomly replace 5 observations in X explanatory variable with outliers drawn from U(15,20) in sample size n=100. The replacement subject to y < 15. The ultimate goal of my study is to