Loop in R does not convert array values -
i typically work in stata i'm new r. seek understand how run loops after reading quite few tutorials, error.
i seek run this:
foo = seq(0, 15000, = 1000) (i in foo){ dbuf <- ei(formula=formula,total="n",data=filename_[i], erho=0.5, id="firm_unique") }
i want run ei function filename_0, filename_1000, filename_2000, , on...
however, get:
error in ei.estimate(t, x, n, id = id, info = data, zb = zb, zw = zw, : object 'sa3eu_ei_' not found
so loop variable not insert 1 of array values loop... thought why happens?
thanks much!
edit additional info:
filename csv file imported info frame
ei statistical program: http://gking.harvard.edu/eir
> dput(formula) dsntpct ~ freeflt > dput(ei) function (formula, total = null, zb = 1, zw = 1, id = na, info = na, erho = 0.5, esigma = 0.5, ebeta = 0.5, ealphab = na, ealphaw = na, truth = na, simulate = true, covariate = null, lambda1 = 4, lambda2 = 2, covariate.prior.list = null, tune.list = null, start.list = null, sample = 1000, lean = 1, burnin = 1000, verbose = 0, ret.beta = "r", ret.mcmc = true, usrfun = null) { dv <- terms.formula(formula)[[2]] iv <- terms.formula(formula)[[3]] t <- as.character(dv) x <- as.character(iv) n <- as.character(total) id <- as.character(id) if (length(dv) == 1) { print("running 2x2 ei") if (simulate == false) { dbuf <- ei.estimate(t, x, n, id = id, info = data, zb = zb, zw = zw, erho = erho, esigma = esigma, ebeta = ebeta, ealphab = ealphab, ealphaw = ealphaw, truth = truth) return(dbuf) } if (simulate == true) { dbuf <- trycatch(trycatch(ei.estimate(t, x, n, id = id, info = data, zb = zb, zw = zw, erho = erho, esigma = esigma, ebeta = ebeta, ealphab = ealphab, ealphaw = ealphaw, truth = truth), error = function(x) ei(t, x, n, id = id, info = data, zb = zb, zw = zw, erho = 3, esigma = esigma, ebeta = ebeta, ealphab = ealphab, ealphaw = ealphaw, truth = truth)), error = function(x) ei.estimate(t, x, n, id = id, info = data, zb = zb, zw = zw, erho = 5, esigma = esigma, ebeta = ebeta, ealphab = ealphab, ealphaw = ealphaw, truth = truth)) dbuf.sim <- ei.sim(dbuf) return(dbuf.sim) } } if (length(dv) > 1) { print("running eirxc") dbuf <- ei.md.bayes(formula, info = data, total = total, covariate = covariate, lambda1 = lambda1, lambda2 = lambda2, covariate.prior.list = covariate.prior.list, tune.list = tune.list, start.list = start.list, sample = sample, lean = thin, burnin = burnin, verbose = verbose, ret.beta = ret.beta, ret.mcmc = ret.mcmc, usrfun = usrfun) dbuf$data <- info dbuf$total <- n dbuf$formula <- formula class(dbuf) <- "ei" return(dbuf) } } >
this might work:
foo = seq(0, 15000, = 1000) dbuf= list() (i in foo){ dbuf[i] <- ei(formula=formula, total="n", data=get(paste0(filename_", i) ), erho=0.5, id="firm_unique") }
two crucial things forgot: 1) need initialize list want utilize indexed assignments , 2) index assignments. otherwise lastly set of results ei()...)
-call. get
function returns named object argument character value.
arrays r loops
No comments:
Post a Comment