[R] Simulation Function - Save results
MarcioRibeiro
mestat at pop.com.br
Fri Aug 14 22:15:55 CEST 2009
Hi listers,
I am working on a simulation... But I am having some troubles...
Suppose I have a function A which produces two results (mean and
variance)...
Then I would like to simulate this function A with a function B many times
using the results from function A
For example:
#Function A
boot<-function(a,b,c){
mean_boot<-(a+b)/2
var_boot<-c
#list(a=a,b=b,c=c)
return(a)
}
Then I would like to create 2 vectors with the mean and var results from S
simulations
#Function B
simul<-function(S){
teste<-rep(0,S)
for(i in 1:S){
teste[i]<-boot(10,12,15) #ACCORDING TO FUNCTION A I AM SAVING JUST THE
MEAN_BOOT, BUT I ALSO NEED THE RESULT OF VAR_BOOT
}
var<-var(teste)
mean_emp<-mean(var_boot) #THIS IS NOT WORKING, BECAUSE I DONT HAVE THE
VAR_BOOT AT MY VECTOR
var_emp<-(sum((var_boot-var)**2))/S #THIS IS NOT WORKING, BECAUSE I DONT
HAVE THE VAR_BOOT AT MY VECTOR
}
simul(5)
But my problem is that I don't know how to save my results in 2 vectors in
order to use then at function B.
Thanks in advance,
Marcio
--
View this message in context: http://www.nabble.com/Simulation-Function---Save-results-tp24977851p24977851.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list