[R] Monte Carlo simulation for ratio and its CI

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Tue Mar 26 00:50:45 CET 2019


> ratio1 <- with(dat, sum(v1,na.rm = TRUE)/sum(v3,na.rm=TRUE))
> ratio1
[1] 1.2

It looks like you should spend some more time with an R tutorial or two.
This is basic stuff (if I understand what you wanted correctly).

Also, this is not how a "confidence interval" should be calculated, but
that is another off topic discussion for which stats.stackexchange.com is a
more appropriate venue.

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Mar 25, 2019 at 4:31 PM Marna Wagley <marna.wagley using gmail.com> wrote:

> Hi R User,
> I was trying to calculate ratios with confidence interval using Monte Carlo
> simulation but I could not figure it out.
> Here is the example of my data (see below), I want to calculate ratios
> (dat$v1/dat$v3 & dat$v2/dat$v3) and its confidence intervals using a 100
> randomly selected data sets.
> Could you please give me your suggestions how I can estimate ratios with
> CI?
> I will be very grateful to you.
> Sincerely,
>
> MW
> ---
> dat<-structure(list(v1 = c(NA, TRUE, TRUE, TRUE, TRUE, TRUE, NA, TRUE,
>
> NA, NA, TRUE, TRUE, TRUE, TRUE, NA, NA, TRUE, TRUE), v2 = c(TRUE,
>
> NA, NA, NA, NA, TRUE, NA, NA, TRUE, TRUE, NA, TRUE, TRUE, NA,
>
> NA, TRUE, TRUE, NA), v3 = c(TRUE, TRUE, NA, TRUE, TRUE, NA, NA,
>
> TRUE, TRUE, NA, NA, TRUE, TRUE, TRUE, NA, NA, TRUE, NA)), .Names = c("v1",
>
> "v2", "v3"), class = "data.frame", row.names = c(NA, -18L))
>
>
> ratio1<-length(which(dat$v1 == "TRUE"))/length(which(dat$v3 == "TRUE"))
>
> ratio2<-length(which(dat$v2 == "TRUE"))/length(which(dat$v3 == "TRUE"))
>
>
> Thanks
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list