[R] problem in loop

Scott Sherrill-Mix shescott at mail.med.upenn.edu
Wed Sep 2 22:56:24 CEST 2009


I'm not too familiar with geese but it looks like the
summary(fit)$correlation would be a dataframe. Maybe try getting the
first (or whatever row you're interested in):
...
corr_gee<-summary(fit)$correlation[1,1]
se_corrgee<-summary(fit)$correlation[1,2]
est[i,]<-c(corr_gee, se_corrgee)
...


Scott

Scott Sherrill-Mix
Department of Microbiology
University of Pennsylvania
425 Johnson Pavilion
3610 Hamilton Walk
Philadelphia, PA  19104-6076
Phone: (215) 573-3141



On Wed, Sep 2, 2009 at 4:45 PM, milton ruser<milton.ruser at gmail.com> wrote:
> Hi there,
>
> and how about this:
>
> nsim<-500
> est<-NULL
> for(i in 1:nsim){
> fit <- geese(x ~ trt, id=subject, data=data_gee, family=binomial,
> corstr="exch", scale.fix=TRUE)
> .............
> corr_gee<-summary(fit)$correlation[1]
> se_corrgee<-summary(fit)$correlation[2]
> est<-data.frame(rbind(est,cbind(corr_gee, se_corrgee)))
> }
>
> or may be if you change c() by cbind() may also work
> on your example.
> bests
> milton
>
>
>
> On Wed, Sep 2, 2009 at 2:20 PM, Seunghee Baek
> <seunghee at mail.med.upenn.edu>wrote:
>
>> Hi R-users,
>> I have a problem for updating the estimates of correlation coefficient in
>> simulation loop.
>> I want to get the matrix of correlation coefficients (matrix, name: est)
>> from geese by using loop(500 times) .
>> I used following code to update,
>>
>> nsim<-500
>> est<-matrix(ncol=2, nrow=nsim)
>> for(i in 1:nsim){
>>
>> fit <- geese(x ~ trt, id=subject, data=data_gee, family=binomial,
>> corstr="exch", scale.fix=TRUE)
>> .............
>> corr_gee<-summary(fit)$correlation[1]
>> se_corrgee<-summary(fit)$correlation[2]
>> est[i,]<-c(corr_gee, se_corrgee)
>> }
>>
>> But, I got an error message : number of subsript in matrix does not match.
>>
>> Can somebody help me? I think sumary(fit)$correlation[1] print out the name
>> of estimates.
>> I guess it might cause problem to be updated in matrix.
>> I want to know other way to print out the estimates of correlation if it
>> helps.
>>
>> Thanks,
>> Becky
>>
>> ______________________________________________
>> R-help at 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<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>




More information about the R-help mailing list