<bestFitLine>
<bestFitLine> is a Graphical
component that computes a linear regression through a list of points.
When nested inside a <graph>, the <bestFitLine> component displays a line.
The equation for the line of best fit can be rendered by accessing the equation property.
Attributes and Properties
Attributes for <bestFitLine>
Number display (5)
avoidScientificNotationAdded in 0.7.16boolean. Default value: false. Whether to render numbers in full decimal form rather than scientific notation.
displayDecimalsinteger. Default value: 2. Number of decimal places to display when rendering this number.
displayDigitsinteger. Default value: 3. Number of significant digits to display when rendering this number.
displaySmallAsZeronumber. Default value: 1e-14. Threshold below which numbers are displayed as zero.
padZerosboolean. Default value: false. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.
Labels (1)
labelIsNameboolean. Default value: false. Whether to use this component's name as its rendered label.
Other (10)
applyStyleToLabelboolean. Default value: false. Whether to apply this component's selected style to its label.
[ pointList ]. The data points to fit a line to.
labelPositionkeyword. Where the label sits along this line/curve.
| Value | Description |
|---|---|
upperRightAdded in 0.7.10 | Place the label above and to the right of the line. |
upperLeftAdded in 0.7.10 | Place the label above and to the left of the line. |
lowerRightAdded in 0.7.10 | Place the label below and to the right of the line. |
lowerLeftAdded in 0.7.10 | Place the label below and to the left of the line. |
center (default)Added in 0.7.10 | Place the label at the midpoint of the line. |
topAdded in 0.7.10 | Place the label directly above the line. |
bottomAdded in 0.7.10 | Place the label directly below the line. |
leftAdded in 0.7.10 | Place the label directly to the left of the line. |
rightAdded in 0.7.10 | Place the label directly to the right of the line. |
layerinteger. Default value: 0. Z-order layer index used to stack graphical components (higher values render on top).
lineStyleAdded in 0.7.18keyword. Stroke style for lines.
| Value | Description |
|---|---|
solid | Continuous, unbroken stroke. |
dashed | Stroke composed of evenly-spaced dashes. |
dotted | Stroke composed of evenly-spaced dots. |
lineWidthAdded in 0.7.18number. Stroke width for lines, in pixels.
maskLabelAdded in 0.7.21boolean. Default value: false. Whether to give the label an opaque background so it stays legible when it overlaps an axis, grid line, or another object.
parallelTo_directionComponent. Direction the line should be parallel to (e.g. another line or vector).
perpendicularTo_directionComponent. Direction the line should be perpendicular to (e.g. another line or vector).
[ _variableNameList ]. Names of the variables used in the line equation.
Common to all components (9)
copyreference. Create an independent copy of another component by reference. Enter a references a $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedboolean. Default value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. Default value: 1. The style number used to select this component's visual styling from the available style definitions.
Properties for <bestFitLine name="b">
Number display (5)
$b.avoidScientificNotationAdded in 0.7.16boolean. Whether to render numbers in full decimal form rather than scientific notation.
$b.displayDecimalsinteger. Number of decimal places to display when rendering this number.
$b.displayDigitsinteger. Number of significant digits to display when rendering this number.
$b.displaySmallAsZeronumber. Threshold below which numbers are displayed as zero.
$b.padZerosboolean. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.
Labels (2)
$b.labellabel. The label rendered with this component.
$b.labelIsNameboolean. Whether to use this component's name as its rendered label.
Other (23)
$b.applyStyleToLabelboolean. Whether to apply this component's selected style to its label.
$b.backgroundColortext. Human-readable name for this component's background color, derived from the active style and theme.
$b.coeff0math. The constant term in the implicit line equation coeff0 + coeffvar1·x + coeffvar2·y = 0.
$b.coeffvar1math. The coefficient of the first variable in the implicit line equation coeff0 + coeffvar1·x + coeffvar2·y = 0.
$b.coeffvar2math. The coefficient of the second variable in the implicit line equation coeff0 + coeffvar1·x + coeffvar2·y = 0.
$b.data[ math ]. The data points used to compute the best-fit line.
$b.draggableboolean. Whether the line can be dragged (always false for a best-fit line).
$b.equationmath. The line's equation as a math expression.
$b.labelPositiontext. Where the label sits along this line/curve.
$b.latexlatex. The line's equation rendered as LaTeX.
$b.layerinteger. Z-order layer index used to stack graphical components (higher values render on top).
$b.maskLabelAdded in 0.7.21boolean. Whether to give the label an opaque background so it stays legible when it overlaps an axis, grid line, or another object.
number. Number of dimensions of the line (always 2 for a best-fit line).
$b.points[ math ]. Two points the line passes through.
$b.slopemath. The slope of the line (2D only).
$b.styleDescriptiontext. A textual description of the line's style.
$b.styleDescriptionWithNountext. Style description including the noun "line".
$b.texttext. The line's equation rendered as plain text.
$b.textColortext. Human-readable name for this component's text color, derived from the active style and theme.
$b.textStyleDescriptiontext. Human-readable description of this component's text styling (color and any background color).
$b.variables[ _variableName ]. Variable names used in the line's equation.
$b.xinterceptmath. The x-intercept of the line.
$b.yinterceptmath. The y-intercept of the line.
Common to all components (8)
$b.disabledboolean. Whether this component is disabled and cannot be interacted with.
$b.doenetMLtext. The DoenetML source code that produced this component.
$b.fixedboolean. Whether this component's value is fixed and cannot be modified.
$b.fixLocationboolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
$b.hideboolean. Whether to hide this component from the rendered output.
$b.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$b.styleNumberinteger. The style number used to select this component's visual styling from the available style definitions.
Examples
Example: <bestFitLine> through 3 points
A <bestFitLine> is rendered through three named <point> components.
Note that the data in this example are not specified as fixed and when the points are
moved the regression line will update accordingly.
Example: <bestFitLine> from user-input
A <bestFitLine> is rendered through three named <point> components.
Coordinates for the points are provided by the user with the <mathInput/> component.
Example: Plot data and determine equation
A <bestFitLine> is rendered through an arbitrary number of data points generated with a <callAction> component that adds <point> children to the named <graph>.
The <collect> component gathers the information required from the <graph> to provide to the data attribute of the <bestFitLine> without having to assign individual names to each <point>.
Attribute Examples
Attribute Example: data
The data attribute specifies the data points through which to fit a regression.
Attribute Example: variables
The variables attribute allows customization of the independent and
dependent variable name when rendering the equation of the computed regression line.
Property Examples
Property Example: equation
The equation property of the named <bestFitLine> renders the
equation of the computed regression line.
Property Example: slope
The slope property of the named <bestFitLine> renders the slope of the computed regression line.
Property Example: coeff0, coeffVar1, coeffVar2
Linear coefficients corresponding to the linear form
coeff0, coeffVar2 and coeffVar1.
Property Example: xIntercept, yIntercept
Use the xIntercept and yIntercept properties of the named <bestFitLine> to determine the
intercepts of the computed regression line.
Property Example: latex
The latex property renders the latex code for rendering the equation of the computed regression line.
Property Example: data
The data property renders two through points computed for the linear regression.
Property Example: variables
The variables property renders the two variables used when rendering the
equation for the linear regression.
Property Example: numDimensions
The numDimensions property renders the number of dimensions for the linear regression.