[R] scope of data in groupedData
Jim Garrett
gaidar_garrett at yahoo.com
Mon Nov 19 20:59:53 CET 2001
I'm trying to write a function that has a dataframe as
an argument. Within the function, I call groupedData
to create a grouped-data object from the dataframe
argument. However, the groupedData function doesn't
seem to see the data. I'm guessing it's getting the
argument name rather than its value, but I'm not
positive.
My system: R 1.3.1 on WinNT 4.0 (Pentium II), nlme
version 3.1-17.
My goal: see below if curious.
My code: (apologies for the very narrow format)
# theta: parameter specifying which indicators
# to use, i.e., specifying the model
# in.dat: data frame to which to fit the model.
# Groups: Maximum possible number of groups
# represented in the data.
# param.orderings: order of group means and SD's, not
# relevant to this question.
# k: complexity cost for AIC
# BIC: Use BIC rather than AIC (and ignore k).
gls.loss <-
function(theta, in.dat, Groups,
param.orderings, k = 2, BIC = T)
{
...
if(any(theta[1:(Groups - 1)] == 1))
{
# partition wells into groups by mu
mu.ind <-
make.indicators(temp.params$well,
temp.params$mu, in.dat)
# error definitely occurs in the next line:
new.dat.gpd <-
groupedData(y ~ Well | Inst / tier,
outer = ~ mu.ind, data = in.dat)
...
}
An example (all arguments are already defined):
> gls.loss(theta, test.dat, 6, param.orderings,
BIC = T)
Error in inherits(data, "data.frame") : Object
"in.dat" not found
I've traced the error to the function nmGroupedData,
specifically:
if (missing(data)) {
...
}
else {
# error at next line
if (!inherits(data, "data.frame")) {
stop("second argument to groupedData must
inherit from data.frame")
....
Any help is welcome!
Finally, here is my overall goal (and I'll also
welcome questions and comments regarding this goal):
I have data comprised of several groups. For each
observation in each group I have a
normally-distributed response, and groups may or may
not differ in mean and/or variance. Using the
varIdent function for weights with gls or lme looks
like a way to model both mean and variance, and I'd
like to "cluster" these groups by finding a
parsimonious (but effective) model. That is, I plan
to create indicator variables for each group and use
model-selection techniques to determine what "group
grouping" is warranted (hoping that most will be
similar!). The model-selection technique I have in
mind is to use simulated annealing to find the model
optimizing BIC or AIC. I've got the SA aspect of this
covered, and my last obstacle is getting a working
loss function. Any comments or questions regarding
this overall goal are also welcomed.
Thanks in advance,
Jim Garrett
Becton Dickinson Diagnostic Systems
Baltimore, Maryland, USA
__________________________________________________
Find the one for you at Yahoo! Personals
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list