[R] Indexing in summaryBy

Julian Wucherpfennig wucherpfennig at icr.gess.ethz.ch
Tue May 15 12:04:45 CEST 2012


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.



More information about the R-help mailing list