Difference between revisions of "Software tutorial/Transformation of data in a linear model"
Jump to navigation
Jump to search
Kevin Dunn (talk | contribs) (Created page with "{{Navigation|Book=Software tutorial|previous=Testing a linear model in R|current=Tutorial index|next=Investigating outliers, discrepancies and other influential points}} __NOT...") |
Kevin Dunn (talk | contribs) m |
||
(4 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
- Desired model | - Desired model | ||
- Formula function in R | - Formula function in R | ||
* - Fit only an intercept | |||
- :math:`y = b_0` | |||
- ``lm(y ~ 1)`` *the character is a "one"* | |||
* - Standard, univariate model | * - Standard, univariate model | ||
- :math:`y = b_0 + b_1 x` | - :math:`y = b_0 + b_1 x` | ||
Line 21: | Line 24: | ||
- ``lm(y ~ x + 0)`` | - ``lm(y ~ x + 0)`` | ||
* - Transformation of an :math:`x` | * - Transformation of an :math:`x` | ||
- :math:`y = b_0 + \sqrt{x}` | - :math:`y = b_0 + b_1\sqrt{x}` | ||
- ``lm(y ~ sqrt(x))`` | - ``lm(y ~ sqrt(x))`` | ||
* - Transformation of :math:`y` | * - Transformation of :math:`y` | ||
Line 30: | Line 33: | ||
- ``lm(100/y ~ x)`` | - ``lm(100/y ~ x)`` | ||
* - Transformation of :math:`x`: **+, -, /, and ^ do not work on the right hand side!** | * - Transformation of :math:`x`: **+, -, /, and ^ do not work on the right hand side!** | ||
- :math:`y= b_0 + b_1 | - :math:`y= b_0 + \dfrac{b_1}{x}` | ||
- ``lm(y ~ | - ``lm(y ~ 1/x)`` *will work, but is not doing what you expect*. It is fitting a model :math:`y = b_0`!! Be careful. | ||
* - Most transformations of :math:`x` must be wrapped in an AsIs ``I()`` operation: | * - Most transformations of :math:`x` must be wrapped in an AsIs ``I()`` operation: | ||
- :math:`y= b_0 + b_1 | - :math:`y= b_0 + \dfrac{b_1}{x}` | ||
- ``lm(y ~ I( | - ``lm(y ~ I(1/x))`` *will work as expected* | ||
* - Another use of the AsIs ``I()`` operation | * - Another use of the AsIs ``I()`` operation | ||
- :math:`y= b_0 + b_1 x^2` | - :math:`y= b_0 + b_1 x^2` |
Latest revision as of 15:49, 28 February 2013
<rst>
<rst-options: 'toc' = False/>
<rst-options: 'reset-figures' = False/>
This is shown by example for a few different types of transformations:
.. list-table::
:widths: 15 10 30 :header-rows: 1
* - Description - Desired model - Formula function in R * - Fit only an intercept - :math:`y = b_0` - ``lm(y ~ 1)`` *the character is a "one"* * - Standard, univariate model - :math:`y = b_0 + b_1 x` - ``lm(y ~ x)`` * - Force intercept to zero (check the degrees of freedom!) - :math:`y = b_1 x` - ``lm(y ~ x + 0)`` * - Transformation of an :math:`x` - :math:`y = b_0 + b_1\sqrt{x}` - ``lm(y ~ sqrt(x))`` * - Transformation of :math:`y` - :math:`\log(y) = b_0 + b_1 x` - ``lm(log(y) ~ x)`` * - Transformation of :math:`y` - :math:`100/y= b_0 + b_1 x` - ``lm(100/y ~ x)`` * - Transformation of :math:`x`: **+, -, /, and ^ do not work on the right hand side!** - :math:`y= b_0 + \dfrac{b_1}{x}` - ``lm(y ~ 1/x)`` *will work, but is not doing what you expect*. It is fitting a model :math:`y = b_0`!! Be careful. * - Most transformations of :math:`x` must be wrapped in an AsIs ``I()`` operation: - :math:`y= b_0 + \dfrac{b_1}{x}` - ``lm(y ~ I(1/x))`` *will work as expected* * - Another use of the AsIs ``I()`` operation - :math:`y= b_0 + b_1 x^2` - ``lm(y ~ I(x^2))`` * - Another use of the AsIs ``I()`` operation - :math:`y= b_0 + b_1 (x - \bar{x})` - ``lm(y ~ I(x - mean(x)))``
</rst>