Skip to content

Doubt about aov and lm function... bug?

9 messages · Jose Claudio Faria, Peter Dalgaard, Rolf Turner

#
Hi,

The below very strange:

#  a) aov function
av <- aov(Sepal.Length ~ Species, data=iris)

#  Error in parse(text = x) :
#   unexpected symbol in "Sepal(Sepal.Length+Species)Length"

av <- aov(iris[, 1] ~ iris[, 5])
#  summary(av)
#               Df Sum Sq Mean Sq F value Pr(>F)
#  iris[, 5]     2   63.2    31.6     119 <2e-16 ***
#  Residuals   147   39.0     0.3
#  ---
#  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1



#  b) lm function
lm1 <- lm(Sepal.Length ~ Sepal.Width, data=iris)

#  Error in parse(text = x) :
#   unexpected symbol in "Sepal(Sepal.Length+Sepal.Width)Length"

lm1 <- lm(iris[, 1] ~ iris[, 2])
summary(lm1)

#  Call:
#  lm(formula = iris[, 1] ~ iris[, 2])
#
#  Residuals:
#     Min     1Q Median     3Q    Max
#  -1.556 -0.633 -0.112  0.558  2.223
#
#  Coefficients:
#              Estimate Std. Error t value Pr(>|t|)
#  (Intercept)    6.526      0.479   13.63   <2e-16 ***
#  iris[, 2]     -0.223      0.155   -1.44     0.15
#  ---
#  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#
#  Residual standard error: 0.82 on 148 degrees of freedom
#  Multiple R-squared: 0.0138,	Adjusted R-squared: 0.00716
#  F-statistic: 2.07 on 1 and 148 DF,  p-value: 0.152

I'm wrong or is it a bug?

platform       i386-pc-mingw32
arch           i386
os             mingw32
system         i386, mingw32
status         Patched
major          2
minor          8.1
year           2009
month          01
day            22
svn rev        47680
language       R
version.string R version 2.8.1 Patched (2009-01-22 r47680)

Thanks,
#
There is no bug.

Both of your examples work fine for me.  You may have a corrupt
version of ``iris'' somewhere in your search path before ``datasets''.

What does find("iris") tell you?  What does names("iris") tell you?

	cheers,

		Rolf Turner
On 9/04/2009, at 8:16 AM, Jose Claudio Faria wrote:

            
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
#
I've been finding the same problem in all R versions I'm using after
2.6.0 (I think).
[1] ".GlobalEnv"       "package:datasets"

It is really strange...
#
Rolf Turner wrote:
Ditto

You may have a corrupt
Could also be something interfering with the model.frame/model.matrix 
bits. The error message suggests that something did a substitute of ".", 
but I can't offhand see a parse(text=x) construct in any of the usual 
suspects. A traceback() could be informative.
#
# a) aov
Error in parse(text = x) :
  unexpected symbol in "Sepal(Sepal.Length+Species)Length"
13: parse(text = x)
12: eval(parse(text = x)[[1]])
11: formula(eval(parse(text = x)[[1]]))
10: formula.character(object, env = baseenv())
9: formula(object, env = baseenv())
8: as.formula(frml)
7: expand.formula(frml, colnames(data))
6: model.matrix.formula(mt, mf, contrasts)
5: model.matrix(mt, mf, contrasts)
4: lm(formula = Sepal.Length ~ Species, data = iris, singular.ok = TRUE)
3: eval(expr, envir, enclos)
2: eval(lmcall, parent.frame())
1: aov(Sepal.Length ~ Species, data = iris)

# b) lm
Error in parse(text = x) :
  unexpected symbol in "Sepal(Sepal.Length+Sepal.Width)Length"
10: parse(text = x)
9: eval(parse(text = x)[[1]])
8: formula(eval(parse(text = x)[[1]]))
7: formula.character(object, env = baseenv())
6: formula(object, env = baseenv())
5: as.formula(frml)
4: expand.formula(frml, colnames(data))
3: model.matrix.formula(mt, mf, contrasts)
2: model.matrix(mt, mf, contrasts)
1: lm(Sepal.Length ~ Sepal.Width, data = iris)

HTH,
#
Jose Claudio Faria wrote:
Er, I have

 >  getAnywhere(model.matrix.formula)
no object named 'model.matrix.formula' was found
 > methods(model.matrix)
[1] model.matrix.default model.matrix.lm

Where did your model.matrix.formula come from???

	-p

  
    
#
Hi Peter and Rolf,

Many thanks for all!

The "bug" was just found: it is related with the package AlgDesign!
(and I've been loading it from Rprofile.site already for a long long time). :-(

See below:

R version 2.8.1 Patched (2009-01-22 r47680)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Design library by Frank E Harrell Jr

Type library(help='Design'), ?Overview, or ?Design.Overview')
to see overall documentation.

deldir 0.0-7
Call:
   aov(formula = Sepal.Length ~ Species, data = iris)

Terms:
                Species Residuals
Sum of Squares       63        39
Deg. of Freedom       2       147

Residual standard error: 0.51
Estimated effects may be unbalanced
Error in parse(text = x) :
  unexpected symbol in "Sepal(Sepal.Length+Species)Length"

I wonder it is really a small bug. Do you agree?

All the best,
#
On 9/04/2009, at 9:17 AM, Jose Claudio Faria wrote:

            
<snip>
It seems to me that there is a conflict between what lm() does and what
the functions in AlgDesign do.  Presumably they are used for completely
different purposes.  So this isn't a bug as such, it is simply a matter
of arranging things so that the right model.matrix() function gets  
called
in the right circumstances.

Sounds like a job for namespaces (about which I was *complaining*  
recently;
:-) ) although I don't understand these well enough to be sure that they
could help here.  Peter will know, I have every confidence!

	cheers,

		Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
#
Jose Claudio Faria wrote:

            
Yes, in AlgDesign.

I'm always suspicious of things involving parse() - see also fortune(106).