<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EstiloDeEmail17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;}
@page Section1
{size:612.0pt 792.0pt;
margin:70.85pt 3.0cm 70.85pt 3.0cm;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=PT-BR link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-family:"Arial","sans-serif"'>Tentei rodar
e não consegui.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div>
<div>
<p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>>
dput(a[sample(1:nrow(a),100),c("Hosp_Death","SAPS3Pro2")])<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'>Error
in dput(a[sample(1:nrow(a), 100), c("Hosp_Death",
"SAPS3Pro2")]) : <o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:"Arial","sans-serif"'> </span><span
style='font-family:"Arial","sans-serif"'>object 'a' not found<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>Amigos
de R,<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'><o:p> </o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>Eu
estou envolvido num projeto que o coordenador deseja estimar SMR em diversos
subgrupos. Aqui SMR (standardized mortality ratios) é definido como a
quantidade de mortes observadas pela quantidade de mortes esperdas dada a
probabilidade de um modelo de predição de morte. <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'><o:p> </o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>Eu fiz
uma pequena função (abaixo) para estimar os SMRs dentre diversos subgrupos.
Usei uma referencia de um inspirador para montar o ICs, mas percebi que dentre
diversos trabalhos que fazem coisas parecidas a variedade de formulas para
estimativas de CIs para os SMRs varia muito. Assim, como tenho muitos dados,
achei que talvez fosse interessante fazer intervalos de confiança com
bootstrap. Mas eu não estou sabendo ao certo como usar a função, já que a
função pede pesos ou frequencias.<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'><o:p> </o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'><o:p> </o:p></span></p>
</div>
<div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>>
dput(a[sample(1:nrow(a),100),c("Hosp_Death","SAPS3Pro2")])<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>structure(list(Hosp_Death
= c(0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0L,
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>1L,
1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0L,
0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>1L,
0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>1L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L), SAPS3Pro2 = c(0.1205, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.3768,
0.315, 0.3768, 0.0311, 0.0719, 0.1735, 0.75, 0.01, 0.1454, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.1093,
0.0511, 0.0891, 0.3353, 0.0073, 0.0401, 0.0044, 0.0239, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.5246,
0.1591, 0.0453, 0.0511, 0.8715, 0.1735, 0.6037, 0.4405, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.2047,
0.0208, 0.1591, 0.2047, 0.1205, 0.2759, 0.0273, 0.0044, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.2759,
0.0157, 0.0643, 0.2215, 0.2047, 0.1735, 0.1591, 0.0273, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.0062,
0.0311, 0.0157, 0.4192, 0.0643, 0.1735, 0.239, 0.4618, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.0401,
0.0802, 0.0273, 0.0239, 0.0025, 0.0157, 0.0311, 0.0157, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.0719,
0.239, 0.0574, 0.0157, 0.0085, 0.0085, 0.1093, 0.2215, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.1591,
0.0719, 0.0044, 0.8563, 0.0453, 0.2047, 0.1454, 0.0273, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.0891,
0.0802, 0.0239, 0.0135, 0.0802, 0.2571, 0.1735, 0.0157, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.3768,
0.2759, 0.0891, 0.2047, 0.1735, 0.1454, 0.0643, 0.0311, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.0453,
0.2759, 0.0239, 0.0181, 0.4405, 0.0085, 0.0311, 0.1205, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>0.6579,
0.1093)), .Names = c("Hosp_Death", "SAPS3Pro2"), row.names
= c(21875L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>6572L,
48643L, 11869L, 35683L, 48246L, 23919L, 29666L, 3676L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>45549L,
36453L, 14510L, 5082L, 1898L, 41549L, 25481L, 28590L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>38198L,
12822L, 12834L, 33267L, 34088L, 47720L, 30063L, 18326L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>11582L,
11454L, 34960L, 18785L, 11385L, 20605L, 28105L, 25496L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>1607L,
48766L, 36534L, 41868L, 45312L, 37206L, 26927L, 38944L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>21087L,
22343L, 1332L, 11496L, 29485L, 38316L, 4486L, 19757L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>45768L,
33028L, 12205L, 13150L, 41270L, 2780L, 44400L, 19696L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>26015L,
14651L, 39093L, 24905L, 17870L, 35016L, 42851L, 20464L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>33155L,
24924L, 33220L, 15379L, 28989L, 33286L, 34782L, 48534L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>9045L,
20403L, 40222L, 8821L, 31240L, 12465L, 11024L, 24407L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>45729L,
7412L, 22344L, 17737L, 3514L, 2335L, 22491L, 22493L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>14077L,
20346L, 12114L, 36868L, 16431L, 25112L, 31272L, 10877L, <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>14391L,
8422L, 45130L), class = "data.frame")<o:p></o:p></span></p>
</div>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'><o:p> </o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'><o:p> </o:p></span></p>
</div>
<div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>>
SMR <- function(obs.var,pred.var){<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
if(length(obs.var) != length(pred.var)){<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
stop("Length of pred.var and obs.var differ.")<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
}<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
if(any(min(pred.var) <0 | max(pred.var) > 1)){<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
stop("The individual predicted death must range from 0 to
1.")<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
}<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
if(any(levels(as.factor(obs.var)) != c(0,1))){<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
stop("Observed death variable must be coded as 0 and
1.")<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
}<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
O <- length(obs.var[which(obs.var==1)])<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
E <- length(pred.var) * mean(pred.var) <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
SMR <- O / E<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
lowerCL <- O / E * (1 - 1 / (9 * O) - 1.96 / (3 * sqrt(O)))^3 * 100<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
upperCL <- (O + 1) / E * (1 - (1 / (9 * (O + 1))) + 1.96 / (3 *
sqrt(O + 1)))^3 * 100<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
output <- c(SMR=SMR,lower.Cl=lowerCL,upper.Cl=upperCL)<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+
output<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>+ }<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>>
SMR(a$Hosp_Death,a$SAPS3Pro2)<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>
SMR lower.Cl upper.Cl <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>
1.000319 97.855941 102.244112 <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'><o:p> </o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>O
intervalo de confiança abaixo roda mas retorna valores sempre iguais a
zero. <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'><o:p> </o:p></span></p>
</div>
<div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>SMR2
<-
function(a,w=1){length(a$Hosp_Death[which(a$Hosp_Death==1)])*w/(length(a$SAPS3Pro2)
* mean(a$SAPS3Pro2))*w}<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>#
boot(city, ratio, R = 999, stype = "w")<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'><a
href="http://boot.ci">boot.ci</a>(boot(a, SMR2, R = 10, stype =
"w",parallel = "multicore"))<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'>x
<- <a href="http://boot.ci">boot.ci</a>(boot(a, SMR2, R = 10, stype =
"w",parallel = "snow"))<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'><o:p> </o:p></span></p>
</div>
</div>
</div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066'><o:p> </o:p></span></p>
</div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class=MsoNormal><span style='font-family:"Courier New";color:#000066;
background:white'>Pedro Brasil</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br /><br />
<hr style='border:none; color:#909090; background-color:#B0B0B0; height: 1px; width: 99%;' />
<table style='border-collapse:collapse;border:none;'>
<tr>
<td style='border:none;padding:0px 15px 0px 8px'>
<a href="https://www.avast.com/antivirus">
<img border=0 src="http://static.avast.com/emails/avast-mail-stamp.png" alt="Avast logo" />
</a>
</td>
<td>
<p style='color:#3d4d5a; font-family:"Calibri","Verdana","Arial","Helvetica"; font-size:12pt;'>
Este email foi escaneado pelo Avast antivírus.
<br><a href="https://www.avast.com/antivirus">www.avast.com</a>
</p>
</td>
</tr>
</table>
<br />
</body>
</html>