CrimsonDark
CrimsonDark

Reputation: 727

Error in eval(expr, envir, enclos) : object not found with xYplot

I am using Frank Harrell's rms package in R to fit a linear model. When I try to plot the residuals following an ols fit, I get an error saying that an object was not found, despite having successfully included the relevant object/variable in the fit.

str(school.uni)

'data.frame':   18262 obs. of  6 variables:
$ student  : int  206 565 292 602 1391 1230 1292 1111 789 1426 ...
$ entry    : Factor w/ 2 levels "direct","indirect": 1 1 1 1 1 1 1 1 1 1 ...
$ band     : Factor w/ 12 levels "Band45","Band50",..: 1 1 1 1 1 1 1 1 1 1 ...
$ school   : num  5.35 10.8 11.95 12.6 14.3 ...
$ uni      : num  42 32.5 19.5 76.1 29.4 ...
$ school70 : num  -64.7 -59.2 -58 -57.4 -55.7 .

ddist <<- datadist(school.uni)
options( datadist = 'ddist')
fit.ols.all.school.entry <<- ols(uni ~ school70 * entry, x=TRUE, y=TRUE, data=school.uni)
r <- resid( fit.ols.all.school.entry)
xYplot(r ~ fitted(fit.ols.all.school.entry))

The preceding xYplot command produces the expected plot but when I attempt to plot the residuals by entry group, I get an error

xYplot(r ~ fitted(fit.ols.all.school.entry), groups=entry)

Error in eval(expr, envir, enclos) : object 'entry' not found

I would appreciate assistance in finding the problem.

Upvotes: 0

Views: 2799

Answers (1)

Mamoun Benghezal
Mamoun Benghezal

Reputation: 5314

You should try this :

xYplot(r ~ fitted(fit.ols.all.school.entry), groups=school.uni$entry)

or you can use attach(school.uni) after loading the data.

Upvotes: 1

Related Questions