Re: [R] Error in Design package: dataset not found for options(datadist)

From: Frank E Harrell Jr <f.harrell_at_vanderbilt.edu>
Date: Thu, 17 Apr 2008 08:03:24 -0500

Gad Abraham wrote:
> Hi,
>
> Design isn't strictly an R base package, but maybe someone can explain
> the following.
>
> When lrm is called within a function, it can't find the dataset dd:
>
> > library(Design)
> > age <- rnorm(30, 50, 10)
> > cholesterol <- rnorm(30, 200, 25)
> > ch <- cut2(cholesterol, g=5, levels.mean=TRUE)
> > fit <- function(ch, age)
> + {
> + d <- data.frame(ch, age)
> + dd <- datadist(d)
> + options(datadist="dd")
> + lrm(ch ~ age, data=d, x=TRUE, y=TRUE)
> + }
> > fit(ch, age)
> Error in Design(eval(m, sys.parent())) :
> dataset dd not found for options(datadist=)
>
> It works outside a function:
> > d <- data.frame(ch, age)
> > dd <- datadist(d)
> > options(datadist="dd")
> > l <- lrm(ch ~ age, data=d, x=TRUE, y=TRUE)
>
>
> Thanks,
> Gad

My guess is that you'll need to put dd in the global environment, not in fit's environment. At any rate it is inefficient to call datadist every time. Why not call it once for the whole data frame containing all the predictors, at the top of the program?

Also it is inefficient to chop continuous variables. You can use the proportional odds model with continuous ch as a response variable although it will be slow if ch has more than, say, 100 unique values.

Frank

>
>
> > sessionInfo()
> R version 2.6.2 (2008-02-08)
> x86_64-pc-linux-gnu
>
> ...
>
> attached base packages:
> [1] splines stats graphics grDevices utils datasets methods
> [8] base
>
> other attached packages:
> [1] Design_2.1-1 survival_2.34 Hmisc_3.4-3
>
> loaded via a namespace (and not attached):
> [1] cluster_1.11.9 grid_2.6.2 lattice_0.17-4 rcompgen_0.1-17
>

-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University

______________________________________________
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.
Received on Thu 17 Apr 2008 - 13:32:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 18 Apr 2008 - 04:30:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive