Hello, I wish to examine the influence of error in variables on my analyses via error propagation. I have a data frame (x) as follows: id response 1 -121 2 -131 3 -125 etc..... I wish to propagate errors for each row in the data frame, where error is distributed around the value of the response variable. To do this, I wish to simulate 1000 variables for each row in the above data frame. I wrote the following, but suspect that it is not applying the function to each row.... sim<-rnorm(1000,mean=x$response, sd= (rnorm(1000,mean= 9.454398, sd=1.980136))) Do I need to use tapply to have the function iteratively go through each row? Any advice would be appreciated. -Steve [[alternative HTML version deleted]]
Hello, I wish to examine the influence of error in variables on my analyses via error propagation. I have a data frame (x) as follows: id response 1 -121 2 -131 3 -125 etc..... I wish to propagate errors for each row in the data frame, where error is distributed around the value of the response variable. To do this, I wish to simulate 1000 variables for each row in the above data frame. I wrote the following, but suspect that it is not applying the function to each row.... sim<-rnorm(1000,mean=x$response, sd= (rnorm(1000,mean= 9.454398, sd=1.980136))) Do I need to use tapply to have the function iteratively go through each row? Any advice would be appreciated. -Steve
Hi Steve, I think you need to use apply() as in the following tiny example: x <- data.frame(response = c(-121,-131,-135)) apply(x, 1, function(response){rnorm(10, mean = response, sd = rnorm(10, mean = 9.454398, sd = 1.980136))}) Christian