**[R] fp** -- Fractional polynomial regression

__Syntax__

Estimation

**fp** **<***term***>** [**,** *est_options*]**:** *est_cmd*

*est_cmd* may be almost any estimation command that stores the
**e(ll)** result. To confirm whether **fp** works with a specific
*est_cmd*, see the documentation for that *est_cmd*.

Instances of **<***term***>** (with the angle brackets) that occur within
*est_cmd* are replaced in *est_cmd* by a varlist containing the
fractional powers of the variable *term*. These variables will be
named *term***_1**, *term***_2**, ....

**fp** performs *est_cmd* with this substitution, fitting a fractional
polynomial regression in *term*.

*est_cmd* in either this or the following syntax may not contain
other prefix commands; see prefix.

Estimation (alternate syntax)

**fp** **<***term***>(***varname***)** [**,** *est_options*]**:** *est_cmd*

Use this syntax to specify that fractional powers of *varname* are
to be calculated. The fractional polynomial power variables will
still be named *term***_1**, *term***_2**, ....

Replay estimation results

**fp** [**,** *replay_options*]

Create specified fractional polynomial power variables

**fp** __gen__**erate** [*type*] [*newvar* **=**] *varname***^(***numlist***)** [*if*] [*in*] [**,**
*gen_options*]

*est_options* Description
-------------------------------------------------------------------------
Main

*Search*
__pow__**ers(***# # *...* #***)** powers to be searched; default is **powers(-2 -1 -.5**
**0 .5 1 2 3)**
__dim__**ension(***#***)** maximum degree of fractional polynomial; default
is **dimension(2)**

*Or specify*
**fp(***# # *...* #***)** use specified fractional polynomial

*And then specify any of these options*

Options
**classic** perform automatic scaling and centering and omit
comparison table
**replace** replace existing fractional polynomial power
variables named *term***_1**, *term***_2**, ...
**all** generate *term***_1**, *term***_2**, ... in all observations;
default is in observations **if** **esample()**
__scal__**e(***#_a #_b***)** use (*term*+*a*)/*b*; default is to use variable term as
is
__scal__**e** specify *a* and *b* automatically
__cent__**er(***#_c***)** report centered-on-*c* results; default is
uncentered results
__cent__**er** specify *c* to be the mean of (scaled) *term*
**zero** set *term***_1**, *term***_2**, ... to zero if (scaled)
*term*<=0; default is to issue an error message
__catz__**ero** same as **zero** and include *term***_0**=(*term*<=0) among
fractional polynomial power variables

Reporting
*replay_options* specify how results are displayed
-------------------------------------------------------------------------

*replay_options* Description
-------------------------------------------------------------------------
Reporting
**nocompare** do not display model-comparison test results
*reporting_options* any options allowed by *est_cmd* for replaying
estimation results
-------------------------------------------------------------------------

*gen_options* Description
-------------------------------------------------------------------------
Main
**replace** replace existing fractional polynomial power
variables named *term***_1**, *term***_2**, ...
__scal__**e(***#_a #_b***)** use (*term*+*a*)/*b*; default is to use variable term as
is
__scal__**e** specify *a* and *b* automatically
__cent__**er(***#_c***)** report centered-on-*c* results; default is
uncentered results
__cent__**er** specify *c* to be the mean of (scaled) *term*
**zero** set *term***_1**, *term***_2**, ... to zero if (scaled)
*term*<=0; default is to issue an error message
__catz__**ero** same as **zero** and include *term***_0**=(*term*<=0) among
fractional polynomial power variables
-------------------------------------------------------------------------

__Menu__

__fp__

**Statistics > Linear models and related > Fractional polynomials >**
**Fractional polynomial regression**

__fp generate__

**Statistics > Linear models and related > Fractional polynomials >**
**Create fractional polynomial variables**

__Description__

**fp** **<***term***>:** *est_cmd* fits models with the "best"-fitting fractional
polynomial substituted for **<***term***>** wherever it appears in *est_cmd*. **fp**
**<weight>: regress mpg <weight> foreign** would fit a regression model of
**mpg** on a fractional polynomial in **weight** and (linear) **foreign**.

By specifying option **fp()**, you may set the exact powers to be used.
Otherwise, a search through all possible fractional polynomials up to the
degree set by **dimension()** with powers set by **powers()** is performed.

**fp** without arguments redisplays the previous estimation results, just as
typing *est_cmd* would. You can type either one. **fp** will include a
fractional polynomial comparison table.

**fp generate** creates fractional polynomial power variables for a given set
of powers. For instance, **fp <weight>: regress mpg <weight> foreign** might
produce the fractional polynomial **weight**^(-2 -1) and store the
**weight**^(-2) in **weight_1** and **weight**^(-1) in **weight_2**. Typing **fp generate**
**weight^(-2 -1)** would allow you to create the same variables in another
dataset.

See **[R] mfp** for multivariable fractional polynomial models.

__Options for fp__

+-------+
----+ Model +------------------------------------------------------------

**powers(***# # *...* #***)** specifies that a search be performed and details about
the search provided. **powers()** works with the **dimension()** option; see
below. The default is **powers(-2 -1 -.5 0 .5 1 2 3)**.

**dimension(***#***)** specifies the maximum degree of the fractional polynomial to
be searched. The default is **dimension(2)**.

If the defaults for both **powers()** and **dimension()** are used, then the
fractional polynomial could be any of the following 44 possibilities:

*term*^(-2)
*term*^(-1)
.
.
.
*term*^(3)
*term*^(-2), *term*^(-2)
*term*^(-2), *term*^(-1)
.
.
.
*term*^(-2), *term*^(3)
*term*^(-1), *term*^(-2)
.
.
.
*term*^(3), *term*^(3)
**fp(***# # *...* #***)** specifies that no search be performed and that the
fractional polynomial specified be used. **fp()** is an alternative to
**powers()** and **dimension()**.

+---------+
----+ Options +----------------------------------------------------------

**classic** performs automatic scaling and centering and omits the comparison
table. Specifying **classic** is equivalent to specifying **scale**, **center**,
and **nocompare**.

**replace** replaces existing fractional polynomial power variables named
*term***_1**, *term***_2**, ....

**all** specifies that *term***_1**, *term***_2**, ... be filled in for all observations
in the dataset rather than just for those in **e(sample)**.

**scale(***#_a #_b***)** specifies that *term* be scaled in the way specified,
namely, that (*term*+*a*)/*b* be calculated. All values of the scaled term
are required to be greater than zero unless you specify options **zero**
or **catzero**. Values should not be too large or too close to zero,
because by default, cubic powers and squared reciprocal powers will
be considered. When **scale(***a b***)** is specified, values in the variable
*term* are not modified; **fp** merely remembers to scale the values
whenever powers are calculated.

You will probably not use **scale(***a b***)** for values of *a* and *b* that you
create yourself, although you could. It is usually easier just to
**generate** a scaled variable. For instance, if *term* is **age**, and **age** in
your data is required to be greater than or equal to 20, you might
generate an **age5** variable, for use as *term*:

. **generate age5 = (age-19)/5**

**scale(***a b***)** is useful when you previously fit a model using automatic
scaling (option **scale**) in one dataset and now want to create the
fractional polynomials in another. In the first dataset, **fp** with
**scale** added **notes** to the dataset concerning the values of *a* and *b*.
You can see them by typing

. **notes**

You can then use **fp generate, scale(***a b***)** in the second dataset.

The default is to use *term* as it is used in calculating fractional
powers; thus *term*'s values are required to be greater than zero
unless you specify options **zero** or **catzero**. Values should not be too
large, because by default, cubic powers will be considered.

**scale** specifies that *term* be scaled to be greater than zero and not too
large in calculating fractional powers. See *Scaling* under *Remarks* of
**[R] fp** for more details. When **scale** is specified, values in the
variable *term* are not modified; **fp** merely remembers to scale the
values whenever powers are calculated.

**center(***#_c***)** reports results for the fractional polynomial in (scaled)
*term*, centered on *c*. The default is to perform no centering.

*term*^(*p_1*, *p_2*, ..., *p_m*)-*c*^(*p_1*, *p_2*, ..., *p_m*) is reported. This
makes the constant coefficient (intercept) easier to interpret. See
*Centering* under *Remarks* of **[R] fp** for more details.

**center** performs **center(***c***)**, where *c* is the mean of (scaled) *term*.

**zero** and **catzero** specify how nonpositive values of *term* are to be
handled. By default, nonpositive values of *term* are not allowed,
because we will be calculating natural logarithms and fractional
powers of *term*. Thus an error message is issued.

**zero** sets the fractional polynomial value to zero for nonpositive
values of (scaled) *term*.

**catzero** sets the fractional polynomial value to zero for nonpositive
values of (scaled) *term* and includes a dummy variable indicating
where nonpositive values of (scaled) *term* appear in the model.

+-----------+
----+ Reporting +--------------------------------------------------------

**nocompare** suppresses display of the comparison tests.

*reporting_options* are any options allowed by *est_cmd* for replaying
estimation results.

__Options for fp generate__

+------+
----+ Main +-------------------------------------------------------------

**replace** replaces existing fractional polynomial power variables named
*term***_1**, *term***_2**, ....

**scale(***#_a #_b***)** specifies that *term* be scaled in the way specified,
namely, that (*term*+*a*)/*b* be calculated. All values of the scaled term
are required to be greater than zero unless you specify options **zero**
or **catzero**. Values should not be too large or too close to zero,
because by default, cubic powers and squared reciprocal powers will
be considered. When **scale(***a b***)** is specified, values in the variable
*term* are not modified; **fp** merely remembers to scale the values
whenever powers are calculated.

You will probably not use **scale(***a b***)** for values of *a* and *b* that you
create yourself, although you could. It is usually easier just to
**generate** a scaled variable. For instance, if *term* is **age**, and **age** in
your data is required to be greater than or equal to 20, you might
generate an **age5** variable, for use as *term*:

. **generate age5 = (age-19)/5**

**scale(***a b***)** is useful when you previously fit a model using automatic
scaling (option **scale**) in one dataset and now want to create the
fractional polynomials in another. In the first dataset, **fp** with
**scale** added **notes** to the dataset concerning the values of *a* and *b*.
You can see them by typing

. **notes**

You can then use **fp generate, scale(***a b***)** in the second dataset.

The default is to use *term* as it is used in calculating fractional
powers; thus *term*'s values are required to be greater than zero
unless you specify options **zero** or **catzero**. Values should not be too
large, because by default, cubic powers will be considered.

**scale** specifies that *term* be scaled to be greater than zero and not too
large in calculating fractional powers. See *Scaling* under *Remarks* of
**[R] fp** for more details. When **scale** is specified, values in variable
*term* are not modified; **fp** merely remembers to scale the values
whenever powers are calculated.

**center(***#_c***)** reports results for the fractional polynomial in (scaled)
*term*, centered on *c*. The default is to perform no centering.

*term*^(*p_1*, ..., *p_d*)-*c*^(*p_1*, ..., *p_d*) is reported. This makes the
constant coefficient (intercept) easier to interpret. See *Centering*
under *Remarks* of **[R] fp** for more details.

**center** performs **center(***c***)**, where *c* is the mean of (scaled) *term*.

**zero** and **catzero** specify how nonpositive values of *term* are to be
handled. By default, nonpositive values of *term* are not allowed,
because we will be calculating natural logarithms and fractional
powers of *term*. Thus an error message is issued.

**zero** sets the fractional polynomial value to zero for nonpositive
values of (scaled) *term*.

**catzero** sets the fractional polynomial value to zero for nonpositive
values of (scaled) *term* and includes a dummy variable indicating
where nonpositive values of (scaled) *term* appear in the model.

__Examples__

Setup
**. webuse igg**

Fit the optimal second-degree fractional polynomial regression model
**. fp <age>: regress sqrtigg <age>**

Generate a fractional polynomial power variable, using automatic scaling
and centering
**. fp generate double age^(-2 2), center scale replace**

__Stored results__

In addition to the results that *est_cmd* stores, **fp** stores the following
in **e()**:

Scalars
**e(fp_dimension)** degree of fractional polynomial
**e(fp_center_mean)** value used for centering or **.**
**e(fp_scale_a)** value used for scaling or **.**
**e(fp_scale_b)** value used for scaling or **.**
**e(fp_compare_df2)** denominator degree of freedom in F test

Macros
**e(fp_cmd)** **fp, search():** or **fp, powers():**
**e(fp_cmdline)** full **fp** command as typed
**e(fp_variable)** fractional polynomial variable
**e(fp_terms)** generated **fp** variables
**e(fp_gen_cmdline)** **fp generate** command to re-create **e(fp_terms)**
variables
**e(fp_catzero)** **catzero**, if specified
**e(fp_zero)** **zero**, if specified
**e(fp_compare_type)** **F** or **chi2**

Matrices
**e(fp_fp)** powers used in fractional polynomial
**e(fp_compare)** results of model comparisons
**e(fp_compare_stat)** F test statistics
**e(fp_compare_df1)** numerator degree of F test
**e(fp_compare_fp)** powers of comparison models
**e(fp_compare_length)** encoded string for display of row titles
**e(fp_powers)** powers that are searched

**fp generate** stores the following in **r()**:

Scalars
**r(fp_center_mean)** value used for centering or **.**
**r(fp_scale_a)** value used for scaling or **.**
**r(fp_scale_b)** value used for scaling or **.**

Macros
**r(fp_cmdline)** full **fp generate** command as typed
**r(fp_variable)** fractional polynomial variable
**r(fp_terms)** generated **fp** variables
**r(fp_catzero)** **catzero**, if specified
**r(fp_zero)** **zero**, if specified

Matrices
**r(fp_fp)** powers used in fractional polynomial