@@ -34,7 +34,10 @@ Now, let's generate design matrices suitable for regressing ``y`` onto
3434
3535 dmatrices(" y ~ x1 + x2" , data)
3636
37- Notice that an intercept term was automatically added. These are just
37+ The return value is a Python tuple containing two DesignMatrix
38+ objects, the first representing the left-hand side of our formula, and
39+ the second representing the right-hand side. Notice that an intercept
40+ term was automatically added to the right-hand side. These are just
3841ordinary numpy arrays with some extra metadata and a fancy __repr__
3942method attached, so we can pass them directly to a regression function
4043like :func: `np.linalg.lstsq `:
@@ -46,7 +49,7 @@ like :func:`np.linalg.lstsq`:
4649 for name, beta in zip (predictors.design_info.column_names, betas):
4750 print (" %s : %s " % (name, beta))
4851
49- Of course the results aren't very interesting, since this is just
52+ Of course the resulting numbers aren't very interesting, since this is just
5053random data.
5154
5255If you just want the design matrix alone, without the ``y `` values,
@@ -57,8 +60,8 @@ use :func:`dmatrix` and leave off the ``y ~`` part at the beginning:
5760 dmatrix(" x1 + x2" , data)
5861
5962 We'll use dmatrix for the rest of the examples, since seeing the
60- outcome matrix over and over would get boring. The metadata is stored
61- in an extra attribute called ``.design_info ``, which is a
63+ outcome matrix over and over would get boring. This matrix's metadata
64+ is stored in an extra attribute called ``.design_info ``, which is a
6265:class: `DesignInfo ` object you can explore at your leisure:
6366
6467.. ipython ::
@@ -105,7 +108,14 @@ automatically accessible to your code:
105108 dmatrix(" center(x1) + standardize(x2)" , data)
106109
107110 See :mod: `patsy.builtins ` for a complete list of functions made
108- available to formulas.
111+ available to formulas. You can also define your own transformation
112+ functions in the ordinary Python way:
113+
114+ .. ipython :: python
115+
116+ def double (x ):
117+ return 2 * x
118+ dmatrix(" x1 + double(x1)" , data)
109119
110120 Arithmetic transformations are also possible, but you'll need to
111121"protect" them by wrapping them in ``I() ``, so that Patsy knows
0 commit comments