[R] OR estimate
David Winsemius
dwinsemius at comcast.net
Sun Jan 27 18:02:06 CET 2008
"sigalit mangut-leiba" <smangut at gmail.com> wrote in
news:c99f7100801270318q7628e394p65cc6b9ff55a3e82 at mail.gmail.com:
> Hello,
> I have a loop with 1000 repetitions which includes OR computation of
> an exposure factor and outcome.
> I compute OR like this:
>
> t<-table(exposure,outcome)
>
> oddsratio(t)$measure["estimate"]
>
> This gives me the estimates for exposure=0 and exposure=1 but
> exposure=0 is the reference group and i need only the estimate for
> exposure=1.
>
> I specified a matrix OR with 3 columns (for OR estimate and lower
> and upper confidence limits) and 1000 rows
>
> OR[k,]<-oddsratio(t)$measure["estimate"]?
>
> I tried: "exposure==1" or "measure["estimate"]" and it gives me
> missing value "NA".
Things.you.should.learn<-c("Read the posting guidelines",
"When asking question ... specify the package being used",
"Use str() to figure the inner details of objects",
"Provide examples")
> library(epitools)
> tapw <- c("Lowest", "Intermediate", "Highest")
> outc <- c("Case", "Control")
> dat <- matrix(c(2, 29, 35, 64, 12, 6),3,2,byrow=TRUE)
> dimnames(dat) <- list("Tap water exposure" = tapw, "Outcome" = outc)
> oddsratio(dat, rev="c")
$data
Outcome
Tap water exposure Control Case Total
Lowest 29 2 31
Intermediate 64 35 99
Highest 6 12 18
Total 99 49 148
$measure
odds ratio with 95% C.I.
Tap water exposure estimate lower upper
Lowest 1.000000 NA NA
Intermediate 7.355436 2.028317 51.3340
Highest 24.991793 5.139475 210.8298
$p.value
two-sided
Tap water exposure midp.exact fisher.exact chi.square
Lowest NA NA NA
Intermediate 1.018658e-03 0.0012611784 1.857572e-03
Highest 1.357958e-05 0.0000131817 6.858659e-06
$correction
[1] FALSE
attr(,"method")
[1] "median-unbiased estimate & mid-p exact CI"
> ORtbl<-oddsratio(dat, rev="c")
> str(ORtbl)
List of 4
$ data : num [1:4, 1:3] 29 64 6 99 2 35 12 49 31 99 ...
..- attr(*, "dimnames")=List of 2
.. ..$ Tap water exposure: chr [1:4] "Lowest" "Intermediate"
"Highest" "Total"
.. ..$ Outcome : chr [1:3] "Control" "Case" "Total"
$ measure : num [1:3, 1:3] 1.00 7.36 24.99 NA 2.03 ...
..- attr(*, "dimnames")=List of 2
.. ..$ Tap water exposure : chr [1:3] "Lowest" "Intermediate"
"Highest"
.. ..$ odds ratio with 95% C.I.: chr [1:3] "estimate" "lower" "upper"
$ p.value : num [1:3, 1:3] NA 1.02e-03 1.36e-05 NA
1.26e-03 ...
..- attr(*, "dimnames")=List of 2
.. ..$ Tap water exposure: chr [1:3] "Lowest" "Intermediate"
"Highest"
.. ..$ two-sided : chr [1:3] "midp.exact" "fisher.exact"
"chi.square"
$ correction: logi FALSE
- attr(*, "method")= chr "median-unbiased estimate & mid-p exact CI"
# Now that you know that ORtbl os a list with 4 elements,
# assing that list to a new object and it will be simpler
> measure.list <- ORtbl$measure
> measure.list
odds ratio with 95% C.I.
Tap water exposure estimate lower upper
Lowest 1.000000 NA NA
Intermediate 7.355436 2.028317 51.3340
Highest 24.991793 5.139475 210.8298
> measure.list[1,2]
[1] NA
> str(measure.list)
num [1:3, 1:3] 1.00 7.36 24.99 NA 2.03 ...
- attr(*, "dimnames")=List of 2
..$ Tap water exposure : chr [1:3] "Lowest" "Intermediate"
"Highest"
..$ odds ratio with 95% C.I.: chr [1:3] "estimate" "lower" "upper"
> measure.list[1]
[1] 1
> measure.list[1,]
estimate lower upper
1 NA NA
> measure.list[2]
[1] 7.355436
> measure.list[2,1]
[1] 7.355436
> measure.list[1,2]
[1] NA
> measure.list[,1]
Lowest Intermediate Highest
1.000000 7.355436 24.991793
#So you want the first column of the second row of the measure list:
> ORtbl$measure[2,1]
[1] 7.355436
--
David Winsemius
More information about the R-help
mailing list