This code worked fine for me, then did some cleaning up of formatting using ESS (Emacs) and now I get this error, no idea what is causing it, all the brackets/parentheses seem to be balanced. What have I done wrong? Thanks Jim p0.trial01 <- 0.25 TruOR01 <- 0.80 num.patients.01 <- 50 num.trials.01 <- 5 LOR01.het.in <- 0.00 num.sims <- 1 simLOR01 <- vector(length=num.trials.01) simLORSE01 <- vector(length=num.trials.01) simOR01 <- vector(length=num.trials.01) trialnum01 <- vector(length=num.trials.01) x0count <- vector(length = num.trials.01) x1count <- vector(length = num.trials.01) ## Trial 1, comparison of treatment 1 with treatment 0 for (i in 1:num.trials.01) { het01 <- rnorm(1,0,LOR01.het.in) log.odds.ratio.01 <- log(TruOR01) + het01 odds.ratio.01 <- exp (log.odds.ratio.01) p1.trial01 <- (p0.trial01 * odds.ratio.01) / (1 - p0.trial01 + (p0.trial01 * odds.ratio.01)) x0.trial01[i] <- rbinom(1,num.patients.01,p0.trial01) x1.trial01[i] <- rbinom(1,num.patients.01,p1.trial01) trialnum01[i] <- paste ( c ("trial01-"), i, sep="") simLOR01[i] <- log (x1.trial01 * (num.patients.01 - x0.trial01) / ((num.patients.01 - x1.trial01) * x0.trial01)) simLORSE01[i] <- sqrt ( (1/x0.trial01) + (1/(num.patients.01 - x0.trial01)) (1 / x1.trial01) + (1 / (num.patients.01 - x1.trial01))) simOR01[i] <- (x1.trial01 * (num.patients.01 - x0.trial01) / ((num.patients.01 - x1.trial01) * x0.trial01)) } ## Output all results to a data.frame called results results <- data.frame (tn1 = trialnum01, SimOR01 = simOR01, SimLOR01 = simLOR01, SimLORSE01 = simLORSE01, p1trial = p1.trial01, x0count, x1count ) set.seed(9321685) results rm(list=ls()) ==============================Dr. Jim Maas University of East Anglia [[alternative HTML version deleted]]
On Sep 23, 2010, at 14:54 , Maas James Dr (MED) wrote:> This code worked fine for me, then did some cleaning up of formatting using ESS (Emacs) and now I get this error, no idea what is causing it, all the brackets/parentheses seem to be balanced. What have I done wrong?Look for ") (" -- missing a "+", presumably. As a general matter, try using tools like traceback() or options(recover=...) to catch such things in the act. They are quite hard to spot by visual inspection. -pd> Thanks > > Jim > > > > p0.trial01 <- 0.25 > TruOR01 <- 0.80 > num.patients.01 <- 50 > num.trials.01 <- 5 > LOR01.het.in <- 0.00 > num.sims <- 1 > > simLOR01 <- vector(length=num.trials.01) > simLORSE01 <- vector(length=num.trials.01) > simOR01 <- vector(length=num.trials.01) > trialnum01 <- vector(length=num.trials.01) > > x0count <- vector(length = num.trials.01) > x1count <- vector(length = num.trials.01) > > ## Trial 1, comparison of treatment 1 with treatment 0 > > for (i in 1:num.trials.01) { > > het01 <- rnorm(1,0,LOR01.het.in) > log.odds.ratio.01 <- log(TruOR01) + het01 > odds.ratio.01 <- exp (log.odds.ratio.01) > > p1.trial01 <- (p0.trial01 * odds.ratio.01) / (1 - p0.trial01 + > (p0.trial01 * odds.ratio.01)) > > x0.trial01[i] <- rbinom(1,num.patients.01,p0.trial01) > x1.trial01[i] <- rbinom(1,num.patients.01,p1.trial01) > > trialnum01[i] <- paste ( c ("trial01-"), i, sep="") > > simLOR01[i] <- log (x1.trial01 * (num.patients.01 - x0.trial01) / > ((num.patients.01 - x1.trial01) * x0.trial01)) > > simLORSE01[i] <- sqrt ( (1/x0.trial01) + (1/(num.patients.01 - > x0.trial01)) (1 / x1.trial01) + (1 / (num.patients.01 - > x1.trial01))) > > simOR01[i] <- (x1.trial01 * (num.patients.01 - x0.trial01) / > ((num.patients.01 - x1.trial01) * x0.trial01)) > > } > > > ## Output all results to a data.frame called results > > results <- data.frame (tn1 = trialnum01, SimOR01 = simOR01, > SimLOR01 = simLOR01, SimLORSE01 = simLORSE01, > p1trial = p1.trial01, x0count, x1count ) > > set.seed(9321685) > > results > > rm(list=ls()) > > > ==============================> Dr. Jim Maas > University of East Anglia > > [[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.-- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
On 23/09/2010 8:54 AM, Maas James Dr (MED) wrote:> This code worked fine for me, then did some cleaning up of formatting using ESS (Emacs) and now I get this error, no idea what is causing it, all the brackets/parentheses seem to be balanced. What have I done wrong?It would help a lot if you posted the actual error message, and the results of a call to traceback() just after it. We can't run your code (we don't have x0.trial01 and don't know how you created it). Duncan Murdoch> Thanks > > Jim > > > > p0.trial01<- 0.25 > TruOR01<- 0.80 > num.patients.01<- 50 > num.trials.01<- 5 > LOR01.het.in<- 0.00 > num.sims<- 1 > > simLOR01<- vector(length=num.trials.01) > simLORSE01<- vector(length=num.trials.01) > simOR01<- vector(length=num.trials.01) > trialnum01<- vector(length=num.trials.01) > > x0count<- vector(length = num.trials.01) > x1count<- vector(length = num.trials.01) > > ## Trial 1, comparison of treatment 1 with treatment 0 > > for (i in 1:num.trials.01) { > > het01<- rnorm(1,0,LOR01.het.in) > log.odds.ratio.01<- log(TruOR01) + het01 > odds.ratio.01<- exp (log.odds.ratio.01) > > p1.trial01<- (p0.trial01 * odds.ratio.01) / (1 - p0.trial01 + > (p0.trial01 * odds.ratio.01)) > > x0.trial01[i]<- rbinom(1,num.patients.01,p0.trial01) > x1.trial01[i]<- rbinom(1,num.patients.01,p1.trial01) > > trialnum01[i]<- paste ( c ("trial01-"), i, sep="") > > simLOR01[i]<- log (x1.trial01 * (num.patients.01 - x0.trial01) / > ((num.patients.01 - x1.trial01) * x0.trial01)) > > simLORSE01[i]<- sqrt ( (1/x0.trial01) + (1/(num.patients.01 - > x0.trial01)) (1 / x1.trial01) + (1 / (num.patients.01 - > x1.trial01))) > > simOR01[i]<- (x1.trial01 * (num.patients.01 - x0.trial01) / > ((num.patients.01 - x1.trial01) * x0.trial01)) > > } > > > ## Output all results to a data.frame called results > > results<- data.frame (tn1 = trialnum01, SimOR01 = simOR01, > SimLOR01 = simLOR01, SimLORSE01 = simLORSE01, > p1trial = p1.trial01, x0count, x1count ) > > set.seed(9321685) > > results > > rm(list=ls()) > > > ==============================> Dr. Jim Maas > University of East Anglia > > [[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.