[R] Indexing in summaryBy
I'm trying to use a self-written function with the summaryBy function (doBy package). I have lots of data from Monte Carlo experiments comparing different estimators across different (combinations of) parameter values, similar to the following form: colnames(mydata) - c(X, b0, b1, # parameter combination, corresponding (true) parameter values b0.m1, b1.m1, # estimates for estimator 1 b0.m2, b1.m2 # estimates for estimator 2) Thus, X is an id that is constant for a given parameter combination across simulation runs. I need to calculate the root mean squared error. For each estimate I extract the corresponding parameter value from the column name of the estimates: rmse - function(est){ parname - deparse(substitute(est)) par1 - unlist(strsplit(parname, c(\\.)))[1] par2 - eval(parse(text=par1)) sqrt(sum((par2- est)^2) /length(est)) } This works well for subsets (i.e. given parameter combinations), but not inside the summaryBy function because I cannot index properly. data1 - subset(mydata, X==1) rmse(data1$b0.m1) summaryBy(b0.m5 X, data=mydata, FUN=c(mean, rmse)) I would need to be able to index inside the rmse function, i.e. something like: sqrt(sum((par2[X==i]- est)^2) /length(est)) How can I fix this? -- View this message in context: http://r.789695.n4.nabble.com/Indexing-in-summaryBy-tp4630050.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] exact method in coxph
I'm trying to estimate a cox proportional hazards regression for repeated events (in gap time) with time varying covariates. The dataset consists of just around 6000 observations (lines) (110 events). The (stylized) data look as follows: unit dur0 dur1 eventn event ongoing x 1 01 0 0 0 32.23 1 12 0 1 1 35.34 1 01 1 0 1 36.12 1 01 1 1 1 45.83 1 12 2 0 0 32.43 1 23 2 0 0 53.63 1 44 2 1 1 45.48 2 01 0 0 0 14.84 2 12 0 1 1 08.63 A complication here is that units can experience repeated events while previous events are still ongoing. I tried the following: cox1 - coxph( Surv( dur0, dur1, event) ~ strata(eventn) + x) This works fine under the breslow and efron method. However, since I have a fair number of ties, especially of repeated events while previous events are still ongoing, the exact method seems advisable. The help says that the exact method is computationally demanding, but even after days the computing it won't finish. Also, if I include a frailty-term, the exact method gives me results in no time. Is my setup incorrect? Many thanks in advance! - Julian Wucherpfennig PhD Student Political Science ETH Zurich - Swiss Federal Institute of Technology -- View this message in context: http://www.nabble.com/exact-method-in-coxph-tp14883387p14883387.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.