Understanding Linear Models
Imagine we are trying to understand relationships between various things in the real world. Linear models are a very elegant way to describe these relationships in mathematical form.
The basic form is very simple:
Why is it called "linear"? Because if we look at the relationship between and , the relationship forms a straight line. Here acts as a "connector" with dimensions .
Let's get to know the three main players in this model:
- is the result we observe (model response)
- is the value we want to find (model parameters)
- is the input we provide (independent variables)
What's interesting is that although we call it "linear", the relationship with input can actually be complex or curved. Only the relationship with parameter is linear.
From Data to Model
Now, how do we use this model in real life? The process is actually like playing detective with data.
First, we conduct a series of experiments or measurements:
- We choose various values for
- For each of these values, we measure and obtain
- Our goal is to find that can explain all this data
Suppose we perform measurements. For each measurement , we have:
Why use the "approximately equal" sign instead of "equals"? Because in the real world, no measurement is perfect. There's always noise, instrument errors, or other random factors that affect the results.
If we count the total of all data we collect, the amount is . Usually this number is much larger than the number of parameters we want to find (), so .
Our challenge now is how to find the best value of , so that the equation is satisfied as accurately as possible.
When we arrange all this data, a system of equations is formed that looks like this:
This produces a system with matrix of size and vector of size .
Various Forms of Linear Models
Linear models turn out to be very flexible and can take various forms. Let's look at some examples that appear most frequently:
Simple Straight Line
The most basic form is a straight line:
Here we look for two parameters: (intercept) and (slope). This model is suitable when data forms a straight line pattern or nearly straight.
Polynomial Curves
If data forms curved patterns, we can use polynomials:
Although looks nonlinear, remember that what we mean by "linear" is the relationship with parameters .
Repeating Patterns with Trigonometry
For data that has repeating or cyclic patterns, we can use sine and cosine functions:
This model is very useful for analyzing data that has seasonal or periodic patterns.
Multiple Inputs
If the output depends on several inputs simultaneously, we can combine them. For example with two inputs and :
The term captures the interaction between the two inputs.
Multiple Outputs
Sometimes we want to predict several things simultaneously from the same input:
This is like having two linear models running simultaneously.
Real Example from Physics
The general gas equation in physics is:
Here:
- is the pressure we measure
- is the temperature we set
- is the volume we set
- is the number of gas molecules (which we want to determine)
- is a known constant
If we consider and as inputs we can control, and as output we measure, then pressure depends linearly on . This allows us to use linear models to determine the number of gas molecules.
When Models Are Initially Nonlinear
Not all real-world problems are directly linear in form. Sometimes we encounter models where parameters appear in quadratic form, multiplication between parameters, or even in exponential functions:
But don't despair! In many cases, we can "linearize" such models. The method is by using tangent line approximation around a certain point :
With this trick, we replace a complex curve with a straight line that approximates it. The result is an equation that is linear with respect to , so it can be solved with standard linear algebra methods like least squares.
However, this linearization method only works if the nonlinear model is not too "curved" around point . Highly nonlinear models require numerical optimization techniques.