Because R?s formula interpreter doesn?t understand brackets. Try:
lm(speed~1.5*dist,data=cars)
Error in
terms.formula(formula, data = data) :
invalid model formula in ExtractVars
lm(speed~(1.5*dist),data=cars)
Error in
terms.formula(formula, data = data) :
invalid model formula in ExtractVars
lm(speed~I(1.5*dist),data=cars)
Call:
lm(formula = speed ~ I(1.5 * dist), data = cars)
Coefficients:
(Intercept) I(1.5 * dist)
8.2839 0.1104
Hope this helps. jens
From: gov2001-l-bounces at
lists.fas.harvard.edu
[mailto:gov2001-l-bounces at
lists.fas.harvard.edu] On Behalf Of Jeremy Hodgen
Sent: Sunday, March 09, 2008 5:07 PM
To: gov2001-l at
lists.fas.harvard.edu
Subject: Re: [gov2001-l] Section 5 code
why not just use brackets
Jeremy
On 9 Mar 2008, at 15:43, Jens Hainmueller wrote:
Yes you don't necessarily need I() here, but it's a good one to know. It's
mostly used in specifying formula objects in model fitting. So for example
when you run a linear regression you can use this to compute predictors that
are combinations of variables "on the fly" like:
lm(Y~I(X1*X2)+I(X3-2/X4),data=Data)
For formulas I() simply tells R to take precedence of whatever is within the
I() statement. The inside is computed first and then the result is used in
the formula.
Notice that you can also use formulas for plots like:
plot(speed~dist,data=cars)
Hope this helps.
Jens?
From: gov2001-l-bounces at
lists.fas.harvard.edu
[mailto:gov2001-l-bounces at
lists.fas.harvard.edu] On Behalf Of Jeremy Hodgen
Sent: Sunday, March 09, 2008 5:54 AM
To: gov2001-l at
lists.fas.harvard.edu
Subject: [gov2001-l] Section 5 code
I'm going through the section code & I'm trying to figure out why
you've
used I() in drawing the first graph - it doesn't seem to make any difference
if I take this out. I've checked the help files and it isn't a great deal of
help.
Jeremy
Dr Jeremy Hodgen
Senior Lecturer in Mathematics Education
King's College London
Department of Education and Professional Studies
Franklin-Wilkins Building
Waterloo Bridge Wing
150 Stamford Street
London SE1 9NH
Tel: 020 7848 3102
Fax: 020 7848 3182
E-mail: jeremy.hodgen at kcl.ac.uk
_______________________________________________
gov2001-l mailing list
gov2001-l at
lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
Dr Jeremy Hodgen
Senior Lecturer in Mathematics Education
King's College London
Department of Education and Professional Studies
Franklin-Wilkins Building
Waterloo Bridge Wing
150 Stamford Street
London SE1 9NH
Tel: 020 7848 3102
Fax: 020 7848 3182
E-mail: jeremy.hodgen at kcl.ac.uk