On Aug 17, 2009, at 1:40 PM, MarcioRibeiro wrote:
Ok, the LIST function I understood...
I didn't see how you got a "random" input to that function. Would seem
to need one of the r<dist> functions as input.
What I would like now is to simulate this Function A many times (S)
in order
to get S results for the MEAN and for the VARIANCE...
?replicate
Zhiliang Ma wrote:
in order to return more multiple variables, you can put them in a
list
and then return this list.
e.g.
#Function A
boot<-function(a,b,c){
mean_boot<-(a+b)/2
var_boot<-c
list(mean_boot = mean_boot, var_boot = var_boot)
}
out <- boot(1,2,3)
out
$mean_boot
[1] 1.5
$var_boot
[1] 3
On Fri, Aug 14, 2009 at 1:15 PM, MarcioRibeiro<mes...@pop.com.br>
wrote:
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.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
--
View this message in context:
http://www.nabble.com/Simulation-Function---Save-results-tp24977851p25011101.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.