Skip to contentSkip to lesson map

Existence of Linear Combinations

Reading
MMAC Ch 3.3, pp 297-307
Practice
Optional HW 19 Q2.4, Q5.4, and Q11.3.
Lesson map

Objectives

  1. Use errors returned by solve() to determine whether a unique solution exists.
  2. Given a vector equation, use R to determine whether a satisfying linear combination exists.
  3. Given data, write a vector equation representing a linear model that fits perfectly; determine whether it has a solution and what that says about the dataset.

1. Errors from solve()

Objective. Use errors returned by solve() to determine whether a unique solution exists.

Theorem 1 (Number of solutions).

A system of linear equations has exactly one solution, no solution, or infinitely many solutions.

Definition 2 (Unique solution).

A system of linear equations has a unique solution when it has exactly one solution.

The system of the equations x−y=1x - y = 1 and 3x−3y=33x - 3y = 3 has no unique solution, because both (1,0)(1, 0) and (2,1)(2, 1) solve both equations. The definition requires exactly one solution.

With two unknowns, the graph of each equation is a line, and the three cases match the three ways two lines can lie in the plane. In each graph below, xx and yy count two kinds of containers on a pallet. One equation matches the load’s weight in pounds, and the other matches its volume in cubic feet. A case of Meals, Ready-to-Eat (MRE) weighs 22 lb and takes 1 ft3^3, a water can weighs 45 lb and takes 0.9 ft3^3, and a double MRE case weighs 44 lb and takes 2 ft3^3. The first load is MRE cases and water cans, and the second and third are MRE cases and double MRE cases. The first two loads weigh 2230 lb, the third weighs 1474 lb, and each takes 67 ft3^3.

Exactly one solution

Figure

With xx MRE cases and yy water cans, the lines cross at (40,30)(40, 30): the load is 40 MRE cases and 30 water cans.

No solution

Figure

With yy double MRE cases, the lines are parallel: no load weighs 2230 lb and takes 67 ft3^3.

Infinitely many solutions

Figure

With a 1474 lb load, the lines coincide: every point on the line solves both equations, and every whole-number load with x+2y=67x + 2y = 67 has that weight and volume.

The command solve(A, v) (Lesson 18 sheet, section 4) returns the unknowns only when exactly one solution exists. In the other two cases solve() stops with an error. Because the error depends on the matrix alone, solve() prints the same message for a system with no solution and for a system with infinitely many solutions when the two share a matrix.

Example 1

Use solve() to determine whether each system has a unique solution:

(a) x+y=2x−y=0,(b) x+y=22x+2y=4,(c) x+y=22x+2y=5. \text{(a)}\ \begin{aligned} x + y &= 2 \\ x - y &= 0, \end{aligned} \qquad\qquad \text{(b)}\ \begin{aligned} x + y &= 2 \\ 2x + 2y &= 4, \end{aligned} \qquad\qquad \text{(c)}\ \begin{aligned} x + y &= 2 \\ 2x + 2y &= 5. \end{aligned}
ShowHide solution
Figure

(a) The lines cross at (1,1)(1, 1).

Figure

(b) The lines are the same line.

Figure

(c) The lines are parallel.

Solve system (a) in R, with the coefficients of xx as column 1 of the matrix and the coefficients of yy as column 2:

u1 = c(1, 1)
u2 = c(1, -1)
A = matrix(c(u1, u2), nrow = 2, ncol = 2)
v = c(2, 0)
solve(A, v)

The last line prints [1] 1 1: system (a) has a unique solution, x=1x = 1 and y=1y = 1. Systems (b) and (c) share a matrix. Define it once, and run solve() with each target vector:

u1 = c(1, 2)
u2 = c(1, 2)
A = matrix(c(u1, u2), nrow = 2, ncol = 2)
v = c(2, 4)
solve(A, v)
v = c(2, 5)
solve(A, v)

Both calls print the same error:

Error in solve.default(A, v) :
Lapack routine dgesv: system is exactly singular: U[2,2] = 0

Neither (b) nor (c) has a unique solution, because solve() stops with an error for each. System (b) has infinitely many solutions, because its second equation is twice the first and both equations describe one line. System (c) has no solution, because dividing its second equation by 2 gives x+y=2.5x + y = 2.5, which contradicts x+y=2x + y = 2.

Messages from solve().

  • Numbers, such as [1] 1 1
    Exactly one solution exists.
  • Lapack routine dgesv: system is exactly singular: U[2,2] = 0
    No unique solution exists. The system has no solution or infinitely many solutions.
  • system is computationally singular: reciprocal condition number = 1.15648e-17
    R stops without a solution. Because decimal entries carry tiny rounding errors, R can find a number near 0 where exact arithmetic gives 0, and then no unique solution exists. The same message can also appear for a system with exactly one solution when one column is very nearly a linear combination of the others. Writing one equation per component and solving the equations by hand settles which case applies.
  • 'a' (5 x 2) must be square
    R stops with an error, because the matrix is not square. Nothing about the number of solutions follows from this message.

Example 2

Use solve() to determine whether the matrix equation has a unique solution:

(0.10.40.70.20.50.80.30.60.9)(x1x2x3)=(0.50.70.9). \begin{pmatrix*}[r] 0.1 & 0.4 & 0.7 \\ 0.2 & 0.5 & 0.8 \\ 0.3 & 0.6 & 0.9 \end{pmatrix*} \begin{pmatrix*}[r] x_1 \\ x_2 \\ x_3 \end{pmatrix*} = \begin{pmatrix*}[r] 0.5 \\ 0.7 \\ 0.9 \end{pmatrix*}.
ShowHide solution

Define the three columns, the matrix, and the target vector, then run solve():

u1 = c(0.1, 0.2, 0.3)
u2 = c(0.4, 0.5, 0.6)
u3 = c(0.7, 0.8, 0.9)
A = matrix(c(u1, u2, u3), nrow = 3, ncol = 3)
v = c(0.5, 0.7, 0.9)
solve(A, v)

The last line prints

Error in solve.default(A, v) :
system is computationally singular: reciprocal condition number = 5.78241e-18

After a computationally singular message, the number of solutions is still open, and a check of the columns by hand settles it. The columns step by the same amount: every entry of bu‾2\overline{\vphantom{b}u}_2 is 0.3 more than the corresponding entry of bu‾1\overline{\vphantom{b}u}_1, and every entry of bu‾3\overline{\vphantom{b}u}_3 is 0.3 more than the corresponding entry of bu‾2\overline{\vphantom{b}u}_2. Column 3 is therefore a linear combination of columns 1 and 2:

2bu‾2−bu‾1=2(0.40.50.6)−(0.10.20.3)=(0.81.01.2)−(0.10.20.3)=(0.70.80.9)=bu‾3. 2\overline{\vphantom{b}u}_2 - \overline{\vphantom{b}u}_1 = 2\begin{pmatrix*}[r] 0.4 \\ 0.5 \\ 0.6 \end{pmatrix*} - \begin{pmatrix*}[r] 0.1 \\ 0.2 \\ 0.3 \end{pmatrix*} = \begin{pmatrix*}[r] 0.8 \\ 1.0 \\ 1.2 \end{pmatrix*} - \begin{pmatrix*}[r] 0.1 \\ 0.2 \\ 0.3 \end{pmatrix*} = \begin{pmatrix*}[r] 0.7 \\ 0.8 \\ 0.9 \end{pmatrix*} = \overline{\vphantom{b}u}_3.

Two different sets of scalars then give the target vector. The first adds columns 1 and 2:

1bu‾1+1bu‾2+0bu‾3=(0.1+0.40.2+0.50.3+0.6)=(0.50.70.9). 1\overline{\vphantom{b}u}_1 + 1\overline{\vphantom{b}u}_2 + 0\overline{\vphantom{b}u}_3 = \begin{pmatrix*}[r] 0.1 + 0.4 \\ 0.2 + 0.5 \\ 0.3 + 0.6 \end{pmatrix*} = \begin{pmatrix*}[r] 0.5 \\ 0.7 \\ 0.9 \end{pmatrix*}.

The second replaces bu‾3\overline{\vphantom{b}u}_3 by 2bu‾2−bu‾12\overline{\vphantom{b}u}_2 - \overline{\vphantom{b}u}_1:

0bu‾1+3bu‾2−1bu‾3=3bu‾2−(2bu‾2−bu‾1)=bu‾1+bu‾2, 0\overline{\vphantom{b}u}_1 + 3\overline{\vphantom{b}u}_2 - 1\overline{\vphantom{b}u}_3 = 3\overline{\vphantom{b}u}_2 - (2\overline{\vphantom{b}u}_2 - \overline{\vphantom{b}u}_1) = \overline{\vphantom{b}u}_1 + \overline{\vphantom{b}u}_2,

the same combination as the first set. R computes both linear combinations:

1*u1 + 1*u2 + 0*u3
0*u1 + 3*u2 - 1*u3

Both lines print [1] 0.5 0.7 0.9. The matrix equation has more than one solution, and therefore no unique solution exists.

Singular errors in the textbook. Ch 3.3 of the textbook (page 300) explains that a singular error means no solution or infinitely many solutions, and states that the book’s exercises are set up so that the error always means no solution. Exercise 45 of Ch 3.3, which is Example 4 below, is one exception: it gives a singular error and has infinitely many solutions.

Next: 2. Existence of a Linear CombinationLesson map

2. Existence of a Linear Combination

Objective. Given a vector equation, use R to determine whether a satisfying linear combination exists.

Asking whether bv‾\overline{\vphantom{b}v} is a linear combination of bu‾1\overline{\vphantom{b}u}_1 and bu‾2\overline{\vphantom{b}u}_2 is asking whether the vector equation

x1bu‾1+x2bu‾2=bv‾ x_1\overline{\vphantom{b}u}_1 + x_2\overline{\vphantom{b}u}_2 = \overline{\vphantom{b}v}

has a solution. With bu‾1\overline{\vphantom{b}u}_1 and bu‾2\overline{\vphantom{b}u}_2 as the columns of AA, the vector equation becomes the matrix equation Abx‾=bv‾A\overline{\vphantom{b}x} = \overline{\vphantom{b}v}, with the vector of unknowns bx‾=(x1x2)\overline{\vphantom{b}x} = \left(\begin{smallmatrix} x_1\\x_2 \end{smallmatrix}\right). When AA is square, the command solve(A, v) returns the scalars when exactly one set exists.

Existence of a linear combination.

  1. Make the vectors the columns of AA, and run solve(A, v).
  2. If R prints numbers, bv‾\overline{\vphantom{b}v} is a linear combination in exactly one way.
  3. If R prints a singular error, or AA is not square, write one equation per component and solve the equations by hand.
  4. If the equations contradict each other, bv‾\overline{\vphantom{b}v} is not a linear combination. If a scalar can take every value and the others follow from it, bv‾\overline{\vphantom{b}v} is a linear combination in infinitely many ways.

Numerical output. When solve(A, v) prints numbers, the vector bv‾\overline{\vphantom{b}v} is a linear combination of bu‾1\overline{\vphantom{b}u}_1 and bu‾2\overline{\vphantom{b}u}_2 in exactly one way, with the printed numbers as the scalars. A printout of [1] 1 2, for example, means that bv‾=1bu‾1+2bu‾2\overline{\vphantom{b}v} = 1\overline{\vphantom{b}u}_1 + 2\overline{\vphantom{b}u}_2.

Singular error. When solve(A, v) prints an exactly singular error, no unique set of scalars exists, because bu‾1\overline{\vphantom{b}u}_1 and bu‾2\overline{\vphantom{b}u}_2 lie on one line through the origin. Solving the equations by hand then separates the two cases, as the vectors bu‾1=(13)\overline{\vphantom{b}u}_1 = \left(\begin{smallmatrix} 1\\3 \end{smallmatrix}\right) and bu‾2=(26)\overline{\vphantom{b}u}_2 = \left(\begin{smallmatrix} 2\\6 \end{smallmatrix}\right) show. In each graph the dashed line is the line through the origin that contains every linear combination of bu‾1\overline{\vphantom{b}u}_1 and bu‾2\overline{\vphantom{b}u}_2.

Target vector on the line

Figure

The vector bv‾=(412)\overline{\vphantom{b}v} = \left(\begin{smallmatrix} 4\\12 \end{smallmatrix}\right) lies on the line. The component equations of x1bu‾1+x2bu‾2=bv‾x_1\overline{\vphantom{b}u}_1 + x_2\overline{\vphantom{b}u}_2 = \overline{\vphantom{b}v} are x1+2x2=4x_1 + 2x_2 = 4 and 3x1+6x2=123x_1 + 6x_2 = 12, and the second is three times the first. For every value of x2x_2, the scalars x1=4−2x2x_1 = 4 - 2x_2 and x2x_2 solve both equations. The vector bv‾\overline{\vphantom{b}v} is therefore a linear combination in infinitely many ways.

Target vector off the line

Figure

The vector bv‾=(411)\overline{\vphantom{b}v} = \left(\begin{smallmatrix} 4\\11 \end{smallmatrix}\right) lies off the line. Three times the first component equation, x1+2x2=4x_1 + 2x_2 = 4, gives 3x1+6x2=123x_1 + 6x_2 = 12, which contradicts the second equation, 3x1+6x2=113x_1 + 6x_2 = 11. The vector bv‾\overline{\vphantom{b}v} is therefore not a linear combination of bu‾1\overline{\vphantom{b}u}_1 and bu‾2\overline{\vphantom{b}u}_2.

Example 3

Determine whether bv‾\overline{\vphantom{b}v} is a linear combination of bu‾1\overline{\vphantom{b}u}_1 and bu‾2\overline{\vphantom{b}u}_2:

bv‾=(74),bu‾1=(12),bu‾2=(31). \overline{\vphantom{b}v} = \begin{pmatrix*}[r] 7 \\ 4 \end{pmatrix*}, \qquad \overline{\vphantom{b}u}_1 = \begin{pmatrix*}[r] 1 \\ 2 \end{pmatrix*}, \qquad \overline{\vphantom{b}u}_2 = \begin{pmatrix*}[r] 3 \\ 1 \end{pmatrix*}.
ShowHide solution

By the definition of a linear combination (Lesson 17 sheet), bv‾\overline{\vphantom{b}v} is a linear combination of bu‾1\overline{\vphantom{b}u}_1 and bu‾2\overline{\vphantom{b}u}_2 when scalars x1x_1 and x2x_2 give bv‾=x1bu‾1+x2bu‾2\overline{\vphantom{b}v} = x_1\overline{\vphantom{b}u}_1 + x_2\overline{\vphantom{b}u}_2. Solve the matrix equation Abx‾=bv‾A\overline{\vphantom{b}x} = \overline{\vphantom{b}v} in R, with bu‾1\overline{\vphantom{b}u}_1 and bu‾2\overline{\vphantom{b}u}_2 as the columns of AA:

u1 = c(1, 2)
u2 = c(3, 1)
v = c(7, 4)
A = matrix(c(u1, u2), nrow = 2, ncol = 2)
solve(A, v)

The last line prints [1] 1 2, the only scalars that solve the vector equation. By hand, the two components of bv‾=x1bu‾1+x2bu‾2\overline{\vphantom{b}v} = x_1\overline{\vphantom{b}u}_1 + x_2\overline{\vphantom{b}u}_2 are the equations

7=x1+3x2,4=2x1+x2. 7 = x_1 + 3x_2, \qquad 4 = 2x_1 + x_2.

Solve the second equation for x2x_2 and substitute it into the first:

x2=4−2x1,7=x1+3(4−2x1)=12−5x1,5x1=12−7=5,x1=1. x_2 = 4 - 2x_1, \qquad 7 = x_1 + 3(4 - 2x_1) = 12 - 5x_1, \qquad 5x_1 = 12 - 7 = 5, \qquad x_1 = 1.

Substituting x1=1x_1 = 1 into x2=4−2x1x_2 = 4 - 2x_1 gives x2=2x_2 = 2, the same scalars R found. The vector bv‾\overline{\vphantom{b}v} is a linear combination of bu‾1\overline{\vphantom{b}u}_1 and bu‾2\overline{\vphantom{b}u}_2, with bv‾=1bu‾1+2bu‾2\overline{\vphantom{b}v} = 1\overline{\vphantom{b}u}_1 + 2\overline{\vphantom{b}u}_2. In the figure, 1bu‾1=(12)1\overline{\vphantom{b}u}_1 = \left(\begin{smallmatrix} 1\\2 \end{smallmatrix}\right) runs from the origin, and 2bu‾2=(62)2\overline{\vphantom{b}u}_2 = \left(\begin{smallmatrix} 6\\2 \end{smallmatrix}\right) starts at its tip and ends at bv‾=(74)\overline{\vphantom{b}v} = \left(\begin{smallmatrix} 7\\4 \end{smallmatrix}\right).

Figure

Example 4

Determine whether bv‾\overline{\vphantom{b}v} is a linear combination of bu‾1\overline{\vphantom{b}u}_1, bu‾2\overline{\vphantom{b}u}_2, and bu‾3\overline{\vphantom{b}u}_3:

bv‾=(0.50.30.1),bu‾1=(531),bu‾2=(410),bu‾3=(820). \overline{\vphantom{b}v} = \begin{pmatrix*}[r] 0.5 \\ 0.3 \\ 0.1 \end{pmatrix*}, \qquad \overline{\vphantom{b}u}_1 = \begin{pmatrix*}[r] 5 \\ 3 \\ 1 \end{pmatrix*}, \qquad \overline{\vphantom{b}u}_2 = \begin{pmatrix*}[r] 4 \\ 1 \\ 0 \end{pmatrix*}, \qquad \overline{\vphantom{b}u}_3 = \begin{pmatrix*}[r] 8 \\ 2 \\ 0 \end{pmatrix*}.
ShowHide solution

Solve the matrix equation in R as in Example 3, with the three vectors as the columns of AA:

u1 = c(5, 3, 1)
u2 = c(4, 1, 0)
u3 = c(8, 2, 0)
v = c(0.5, 0.3, 0.1)
A = matrix(c(u1, u2, u3), nrow = 3, ncol = 3)
solve(A, v)

The last line prints

Error in solve.default(A, v) :
Lapack routine dgesv: system is exactly singular: U[3,3] = 0

No unique set of scalars exists, because solve() prints an exactly singular error. By hand, the three components of bv‾=x1bu‾1+x2bu‾2+x3bu‾3\overline{\vphantom{b}v} = x_1\overline{\vphantom{b}u}_1 + x_2\overline{\vphantom{b}u}_2 + x_3\overline{\vphantom{b}u}_3 are the equations

0.5=5x1+4x2+8x3,0.3=3x1+x2+2x3,0.1=x1. 0.5 = 5x_1 + 4x_2 + 8x_3, \qquad 0.3 = 3x_1 + x_2 + 2x_3, \qquad 0.1 = x_1.

Substitute x1=0.1x_1 = 0.1, from the third equation, into the first two:

0.5=5(0.1)+4x2+8x3=0.5+4(x2+2x3),0.3=3(0.1)+x2+2x3. 0.5 = 5(0.1) + 4x_2 + 8x_3 = 0.5 + 4(x_2 + 2x_3), \qquad 0.3 = 3(0.1) + x_2 + 2x_3.

Both reduce to x2+2x3=0x_2 + 2x_3 = 0. For every value of x3x_3, the scalars x1=0.1x_1 = 0.1, x2=−2x3x_2 = -2x_3, and x3x_3 solve all three equations. As a check, the sets for x3=0x_3 = 0 and x3=1x_3 = 1 give the target vector in R:

u1 = c(5, 3, 1)
u2 = c(4, 1, 0)
u3 = c(8, 2, 0)
0.1*u1 + 0*u2 + 0*u3
0.1*u1 - 2*u2 + 1*u3

Both lines print [1] 0.5 0.3 0.1. The vector bv‾\overline{\vphantom{b}v} is a linear combination of bu‾1\overline{\vphantom{b}u}_1, bu‾2\overline{\vphantom{b}u}_2, and bu‾3\overline{\vphantom{b}u}_3 in infinitely many ways, for example bv‾=0.1bu‾1\overline{\vphantom{b}v} = 0.1\overline{\vphantom{b}u}_1.

Example 5

Determine whether bv‾\overline{\vphantom{b}v} is a linear combination of bu‾1\overline{\vphantom{b}u}_1, bu‾2\overline{\vphantom{b}u}_2, and bu‾3\overline{\vphantom{b}u}_3:

bv‾=(231),bu‾1=(012),bu‾2=(110),bu‾3=(220). \overline{\vphantom{b}v} = \begin{pmatrix*}[r] 2 \\ 3 \\ 1 \end{pmatrix*}, \qquad \overline{\vphantom{b}u}_1 = \begin{pmatrix*}[r] 0 \\ 1 \\ 2 \end{pmatrix*}, \qquad \overline{\vphantom{b}u}_2 = \begin{pmatrix*}[r] 1 \\ 1 \\ 0 \end{pmatrix*}, \qquad \overline{\vphantom{b}u}_3 = \begin{pmatrix*}[r] 2 \\ 2 \\ 0 \end{pmatrix*}.
ShowHide solution

Solve the matrix equation in R as in Example 4:

u1 = c(0, 1, 2)
u2 = c(1, 1, 0)
u3 = c(2, 2, 0)
v = c(2, 3, 1)
A = matrix(c(u1, u2, u3), nrow = 3, ncol = 3)
solve(A, v)

The last line prints

Error in solve.default(A, v) :
Lapack routine dgesv: system is exactly singular: U[3,3] = 0

No unique set of scalars exists, because solve() prints an exactly singular error. By hand, the three components give the equations

2=x2+2x3,3=x1+x2+2x3,1=2x1. 2 = x_2 + 2x_3, \qquad 3 = x_1 + x_2 + 2x_3, \qquad 1 = 2x_1.

The third equation gives x1=0.5x_1 = 0.5. Substitute it into the second:

3=0.5+x2+2x3,x2+2x3=3−0.5=2.5, 3 = 0.5 + x_2 + 2x_3, \qquad x_2 + 2x_3 = 3 - 0.5 = 2.5,

which contradicts the first equation, x2+2x3=2x_2 + 2x_3 = 2. The vector bv‾\overline{\vphantom{b}v} is not a linear combination of bu‾1\overline{\vphantom{b}u}_1, bu‾2\overline{\vphantom{b}u}_2, and bu‾3\overline{\vphantom{b}u}_3.

Columns behind a singular error. An exactly singular error means one column of AA is a linear combination of the other columns. In each of Examples 4 and 5, every linear combination of the three columns lies in a single plane, because bu‾3=2bu‾2\overline{\vphantom{b}u}_3 = 2\overline{\vphantom{b}u}_2 and neither of bu‾1\overline{\vphantom{b}u}_1 and bu‾2\overline{\vphantom{b}u}_2 is a scalar multiple of the other. Example 4’s target vector lies in its plane and is a linear combination of the columns. Example 5’s target vector lies off its plane and is not.

Next: 3. Vector Equations for a Perfect FitLesson map

3. Vector Equations for a Perfect Fit

Objective. Given data, write a vector equation representing a linear model that fits perfectly; determine whether it has a solution and what that says about the dataset.

Definition 3 (Perfect fit).

A linear model y=mx+by = mx + b fits a dataset perfectly when every data point satisfies it.

The model y=xy = x does not fit the data points (0,0)(0, 0), (1,1)(1, 1), and (2,3)(2, 3) perfectly. The first two points satisfy it, and the point (2,3)(2, 3) does not, because 3≠23 \neq 2. The definition requires every data point to satisfy the model.

For a dataset of nn data points, each data point (xi,yi)(x_i, y_i), for i=1,2,…,ni = 1, 2, \dots, n, gives one equation yi=mxi+by_i = mx_i + b.

The intercept vector is the vector b1‾n\overline{\vphantom{b}1}_n whose nn components are all 1.

Stacking the nn equations gives one vector equation:

(y1⋮yn)=m(x1⋮xn)+b(1⋮1). \begin{pmatrix*}[r] y_1 \\ \vdots \\ y_n \end{pmatrix*} = m\begin{pmatrix*}[r] x_1 \\ \vdots \\ x_n \end{pmatrix*} + b\begin{pmatrix*}[r] 1 \\ \vdots \\ 1 \end{pmatrix*}.

In the vector equation of a linear model, the outputs form the target vector, the inputs form the input vector that mm multiplies, and bb is the scalar that multiplies the intercept vector.

When n>2n > 2, the matrix equation for this vector equation has a matrix with nn rows and two columns. A matrix that is not square makes solve() stop with an error. When n=2n = 2, the matrix is 2×22 \times 2, and solve() returns mm and bb when the two xx-values differ. Two data points with the same xx-value lie on a vertical line, which has no slope mm, and solve() prints a singular error.

Existence of a perfect fit.

  1. Choose two data points with different xx-values and find the mm and bb of the line through them, by the slope formula or with solve() on the 2×22 \times 2 matrix equation for those two points.
  2. Compute mm times the input vector plus b b1‾nb\,\overline{\vphantom{b}1}_n.
  3. Compare the result with the target vector, component by component. If every component matches, mm and bb solve the vector equation. If one or more components differ, the vector equation has no solution.

Mismatched component. Every solution of the vector equation satisfies the two component equations for the data points chosen to find mm and bb. Because their xx-values differ, those two equations have exactly one solution, the mm and bb of the line through the two points. As a result, when that line misses another data point, the vector equation has no solution.

Verdict about the data. Data are exactly linear when every data point lies on one line. For data with at least two different xx-values, a solution of the vector equation means the data are exactly linear, and no solution means the data are not exactly linear. A linear model can still be reasonable for data that are not exactly linear.

Graphical check. Plot the data with plotPoints() and the line through the two chosen points with plotFun(..., add = TRUE). The plot shows whether the line passes through every data point.

Example 6

The table gives the number of Twitter users, in millions, by quarter, where Year counts years since 2000 and Year=11\text{Year} = 11 is January to March 2011.

Year1111.2511.511.7512.75
Users (millions)6885101117185
  • (a)

    Write the vector equation for a perfect fit of the linear model

    Users=m⋅Year+b. \text{Users} = m \cdot \text{Year} + b.
  • (b) Find mm and bb from the first two data points.
  • (c) Determine algebraically whether mm and bb solve the vector equation, and state the conclusion about the data.
  • (d) Show the answer to part (c) graphically.
ShowHide solution

(a) Writing one equation per data point and stacking the five equations gives the vector equation

(6885101117185)=m(1111.2511.511.7512.75)+b b1‾5. \begin{pmatrix*}[r] 68 \\ 85 \\ 101 \\ 117 \\ 185 \end{pmatrix*} = m\begin{pmatrix*}[r] 11 \\ 11.25 \\ 11.5 \\ 11.75 \\ 12.75 \end{pmatrix*} + b\,\overline{\vphantom{b}1}_5.

(b) Substitute the first two data points, (11,68)(11, 68) and (11.25,85)(11.25, 85), into the slope formula. Then substitute m=68m = 68 and the first data point, Year=11\text{Year} = 11 and Users=68\text{Users} = 68, into Users=m⋅Year+b\text{Users} = m \cdot \text{Year} + b, and solve for bb:

m=85−6811.25−11=170.25=68,b=68−68(11)=68−748=−680. m = \frac{85 - 68}{11.25 - 11} = \frac{17}{0.25} = 68, \qquad b = 68 - 68(11) = 68 - 748 = -680.

In R, solve the 2×22 \times 2 matrix equation formed by the first two components:

u1 = c(11, 11.25)
u2 = c(1, 1)
A = matrix(c(u1, u2), nrow = 2, ncol = 2)
solve(A, c(68, 85))

The last line prints [1]   68 -680: m=68m = 68 and b=−680b = -680.

(c) By the definition of a perfect fit, the model fits only when every data point satisfies it, that is, when mm and bb solve the vector equation. Substituting m=68m = 68 and b=−680b = -680 into the right side gives

68(1111.2511.511.7512.75)−680 b1‾5=(6885102119187)≠(6885101117185). 68\begin{pmatrix*}[r] 11 \\ 11.25 \\ 11.5 \\ 11.75 \\ 12.75 \end{pmatrix*} - 680\,\overline{\vphantom{b}1}_5 = \begin{pmatrix*}[r] 68 \\ 85 \\ 102 \\ 119 \\ 187 \end{pmatrix*} \neq \begin{pmatrix*}[r] 68 \\ 85 \\ 101 \\ 117 \\ 185 \end{pmatrix*}.

R computes the same right side from the vectors Year and Users:

Year = c(11, 11.25, 11.5, 11.75, 12.75)
Users = c(68, 85, 101, 117, 185)
68*Year - 680

The last line prints [1]  68  85 102 119 187. The first two components match the target vector, and the third is 102 where the target vector has 101. The vector equation has no solution, because the third component differs, and therefore the Twitter data are not exactly linear.

(d) Plotting the data with the line through the first two points shows the answer to part (c):

=2.2em Year = c(11, 11.25, 11.5, 11.75, 12.75)
Users = c(68, 85, 101, 117, 185)
plotPoints(Users ~ Year)
f = makeFun(68*x - 680 ~ x)
plotFun(f(x) ~ x, add = TRUE, col = "red")

Figure

The line passes through the first two points and runs above each of the last three, by 1, 2, and 2 million users. Gaps that small are hard to see against an axis that spans more than 100 million users. Zooming the plot in on the last three points shows each one below the line, the graphical sign that the data are not exactly linear.

Example 7

The table lists five temperatures, each in degrees Celsius CC and in degrees Fahrenheit FF.

Celsius CC010203040
Fahrenheit FF32506886104

Write the vector equation for a perfect fit of the linear model

F=mC+b. F = mC + b.

Then find mm and bb from the first and last data points, determine whether they solve the vector equation, and state the conclusion about the data.

ShowHide solution

Writing one equation per data point gives the vector equation

(32506886104)=m(010203040)+b b1‾5. \begin{pmatrix*}[r] 32 \\ 50 \\ 68 \\ 86 \\ 104 \end{pmatrix*} = m\begin{pmatrix*}[r] 0 \\ 10 \\ 20 \\ 30 \\ 40 \end{pmatrix*} + b\,\overline{\vphantom{b}1}_5.

The line through (0,32)(0, 32) and (40,104)(40, 104) has slope and intercept

m=104−3240−0=7240=1.8,b=32, m = \frac{104 - 32}{40 - 0} = \frac{72}{40} = 1.8, \qquad b = 32,

because the first data point has C=0C = 0. Substituting m=1.8m = 1.8 and b=32b = 32 into the right side gives

1.8(010203040)+32 b1‾5=(32506886104). 1.8\begin{pmatrix*}[r] 0 \\ 10 \\ 20 \\ 30 \\ 40 \end{pmatrix*} + 32\,\overline{\vphantom{b}1}_5 = \begin{pmatrix*}[r] 32 \\ 50 \\ 68 \\ 86 \\ 104 \end{pmatrix*}.

Every component matches the target vector. R computes the same right side from the vectors Celsius and Fahrenheit:

Celsius = c(0, 10, 20, 30, 40)
Fahrenheit = c(32, 50, 68, 86, 104)
1.8*Celsius + 32

The last line prints [1]  32  50  68  86 104. The values m=1.8m = 1.8 and b=32b = 32 solve the vector equation. The data are exactly linear, on the line F=1.8C+32F = 1.8C + 32, because every data point satisfies the model. Each column of the table is one plotted point, such as (20,68)(20, 68), and every point lies on the line.

Figure

Lesson map