Hi,
I was trying to calculate an age adjusted rate for which we have the formula
as
sum(weight*rate)/sum(weight). I am using the framingham dataset called fram
here.I cant figure out how I could change the logical statement I have for the
standard dataset (in red) to calculate weight and calculating the wevents and
atrisk(in red)
Below is my code:
attach(fram)
dset1<-cbind(AGE,BMI,DEATH)
BMIGRP1<-cut(BMI,breaks=c(14,20,25,57),right=TRUE)
levels(BMIGRP1)
BMIGRP<-as.numeric(BMIGRP1)
AGEGRP<-floor(AGE/10)-2
dset<-cbind(AGEGRP,BMIGRP,DEATH)
std<-cbind(AGEGRP)
maxage<-max(dset[,1])
minage<-min(dset[,1])
maxcls<-max(dset[,2], na.rm=T)
mincls<-min(dset[,2],na.rm=T)
nage<-maxage-minage+1
nclass<-maxcls-mincls+1
nsub<-nrow(dset)
weight <- matrix(0,nage,1)
for ( i in minage:maxage )
weight[i-minage+1,1] = sum(std=i)
atrisk = matrix(0,nclass,nage)
wevents = matrix(0,nclass,nage)
for( i in minage : maxage)
for( j in mincls : maxcls)
atrisk[j-mincls+1,i-minage+1] =
sum((dset[,1]=i)& (dset[,2]=j))
wevents[j-mincls+1,i-minage+1]=
sum((dset[,1]=i)& (dset[,2]=j)&(dset[,3]=1))
#vtit = char(t(mincls:maxcls),5,0) // {Total};
#htit = {'at risk' 'events' 'rate/1000'};
atrisk2 = atrisk // atrisk[+,1:nage];
event2 = wevents // wevents[+,1:nage];
atrisk3 = choose(atrisk2=0,1,atrisk2);
rate = event2/atrisk3;
this was done using sas macro.
Thanks so much!
---------------------------------
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html