ReferencebestFitLine

<bestFitLine>

The best-fit line for a set of points

<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)
avoidScientificNotation

boolean. Default value: false. Whether to render numbers in full decimal form rather than scientific notation.

displayDecimals

integer. Default value: 2. Number of decimal places to display when rendering this number.

displayDigits

integer. Default value: 3. Number of significant digits to display when rendering this number.

displaySmallAsZero

number. Default value: 1e-14. Threshold below which numbers are displayed as zero.

padZeros

boolean. Default value: false. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.

Labels (1)
labelIsName

boolean. Default value: false. Whether to use this component's name as its rendered label.

Other (9)
applyStyleToLabel

boolean. Default value: false. Whether to apply this component's selected style to its label.

[ pointList ]. The data points to fit a line to.

labelPosition

keyword. Where the label sits along this line/curve.

ValueDescription
upperRightPlace the label above and to the right of the line.
upperLeftPlace the label above and to the left of the line.
lowerRightPlace the label below and to the right of the line.
lowerLeftPlace the label below and to the left of the line.
center (default)Place the label at the midpoint of the line.
topPlace the label directly above the line.
bottomPlace the label directly below the line.
leftPlace the label directly to the left of the line.
rightPlace the label directly to the right of the line.
layer

integer. Default value: 0. Z-order layer index used to stack graphical components (higher values render on top).

lineStyle

keyword. Stroke style for lines.

ValueDescription
solidContinuous, unbroken stroke.
dashedStroke composed of evenly-spaced dashes.
dottedStroke composed of evenly-spaced dots.
lineWidth

number. Stroke width for lines, in pixels.

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)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

boolean. Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. 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.avoidScientificNotation

boolean. Whether to render numbers in full decimal form rather than scientific notation.

$b.displayDecimals

integer. Number of decimal places to display when rendering this number.

$b.displayDigits

integer. Number of significant digits to display when rendering this number.

$b.displaySmallAsZero

number. Threshold below which numbers are displayed as zero.

$b.padZeros

boolean. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.

Labels (2)
$b.label

label. The label rendered with this component.

$b.labelIsName

boolean. Whether to use this component's name as its rendered label.

Other (26)
$b.applyStyleToLabel

boolean. Whether to apply this component's selected style to its label.

$b.backgroundColor

text. Human-readable name for this component's background color, derived from the active style and theme.

math. The constant term in the implicit line equation coeff0 + coeffvar1·x + coeffvar2·y = 0.

math. The coefficient of the first variable in the implicit line equation coeff0 + coeffvar1·x + coeffvar2·y = 0.

math. 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.disabled

boolean. Whether this component is disabled and cannot be interacted with.

$b.draggable

boolean. Whether the line can be dragged (always false for a best-fit line).

math. The line's equation as a math expression.

$b.fixed

boolean. Whether this component's value is fixed and cannot be modified.

$b.fixLocation

boolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

$b.hidden

boolean. Whether this component is hidden from the rendered output.

$b.labelPosition

text. Where the label sits along this line/curve.

latex. The line's equation rendered as LaTeX.

$b.layer

integer. Z-order layer index used to stack graphical components (higher values render on top).

number. Number of dimensions of the line (always 2 for a best-fit line).

$b.points

[ math ]. Two points the line passes through.

math. The slope of the line (2D only).

$b.styleDescription

text. A textual description of the line's style.

$b.styleDescriptionWithNoun

text. Style description including the word "line".

$b.text

text. The line's equation rendered as plain text.

$b.textColor

text. Human-readable name for this component's text color, derived from the active style and theme.

$b.textStyleDescription

text. Human-readable description of this component's text styling (color and any background color).

[ _variableName ]. Variable names used in the line's equation.

math. The x-intercept of the line.

math. The y-intercept of the line.

Common to all components (4)
$b.doenetML

text. The DoenetML source code that produced this component.

$b.hide

boolean. Whether to hide this component from the rendered output.

$b.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$b.styleNumber

integer. 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 A x + B y + C = 0 can be obtained with the above properties, where C=C = coeff0, B=B = coeffVar2 and A=A = 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.