Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 47 lines (44 sloc) 1.885 kb
5af3843 create initial svn
harrelfe authored
1 gendata <- function(fit, ..., nobs, viewvals=FALSE, factors)
2 {
3 at <- fit$Design
4 nam <- at$name[at$assume!="interaction"]
5
6 if(!missing(nobs) && !is.logical(nobs))
7 {
8 df <- predictrms(fit, type="adjto.data.frame")
9 df[1:nobs,] <- df
10 cat("Edit the list of variables you would like to vary.\nBlank out variables to set to reference values.\n")
11 nam.sub <- de(nam)[[1]]
12 nam.sub <- nam.sub[!is.na(nam.sub)]
13 if(!all(nam.sub %in% nam)) stop("misspelled a variable name")
14 df.sub <- as.data.frame(df[,nam.sub])
15 cat("Edit the predictor settings to use.\n")
16 if(viewvals &&
17 length(val <- Getlim(at, allow.null=TRUE,
18 need.all=FALSE)$values[nam.sub]))
19 {
20 cat("A window is being opened to list the valid values of discrete variables.\n")
21 sink(tf <- tempfile())
22 print.datadist(list(values=val))
23 sink()
24 file.show(tf)
25 }
26 for(i in 1:length(df.sub))
27 if(is.factor(df.sub[[i]])) df.sub[[i]] <- as.character(df.sub[[i]])
28 df.sub <- as.data.frame(de(df.sub))
29 df[nam.sub] <- df.sub
30 return(structure(df, names.subset=nam.sub))
31 }
32
33 factors <- if(missing(factors)) rmsArgs(substitute(list(...))) else factors
34 fnam <- names(factors)
35 nf <- length(factors)
36 if(nf==0) return(predictrms(fit, type="adjto.data.frame"))
37 which <- charmatch(fnam, nam, 0)
38 if(any(which==0)) stop(paste("factor(s) not in design:",
39 paste(names(factors)[which==0],collapse=" ")))
40 settings <- if(nf<length(nam)) predictrms(fit, type="adjto.data.frame")
41 else list()
42 settings <- oldUnclass(settings)
43 if(nf>0) for(i in 1:nf) settings[[fnam[i]]] <- factors[[i]]
44 if(nf==0) return(as.data.frame(settings))
45 expand.grid(settings)
46 }
Something went wrong with that request. Please try again.