Multiple regression: Difference between revisions

m
imported>Stevegt
(flag C, Go, and Python as incorrect -- most others are also wrong and apparently cargo-culted from each other, but we have to start somewhere)
m (→‎{{header|Wren}}: Minor tidy)
(2 intermediate revisions by one other user not shown)
Line 12:
<math>y_j = \Sigma_i \beta_i \cdot x_{ij} , j \in 1..n</math>
 
You can assume <i> y </i> is given to you as a vector (a one-dimensional array), and '''<i> X </i> is given to you as a two-dimensional array (i.e. matrix)'''.
<br><br>
 
;Example use case:
 
Think of multiple regression as "surface fitting" rather than curve fitting. For example, you might use multiple regression to create a three-dimensional surface so you can estimate implied volatility given time to maturity and delta of an options contract. For pretty pictures of this, see [https://www.google.com/search?q=+volatility+surface&tbm=isch volatility surface] graphs. In this case, X is a two-dimensional matrix of <code>{time[i], delta[i]}</code>, and Y is a matching list of <code>implied_volatility[i]</code>.
 
;References:
 
* [https://en.wikiversity.org/wiki/Multiple_linear_regression Multiple Regression] page on Wikiversity
* [https://en.wikipedia.org/wiki/Linear_regression#Simple_and_multiple_linear_regression Multiple Regression] description in Wikipedia
 
=={{header|Ada}}==
Line 621 ⟶ 612:
 
=={{header|C}}==
 
{{incorrect|C|X input must be a two-dimensional array. Most examples on this page are wrong -- see task description and Talk.}}
 
Using GNU gsl and c99, with the WP data<syntaxhighlight lang="c">#include <stdio.h>
#include <gsl/gsl_matrix.h>
Line 1,495 ⟶ 1,483:
 
=={{header|Go}}==
 
{{incorrect|Go|X input must be a two-dimensional array. Most examples on this page are wrong -- see task description and Talk.}}
 
The [http://en.wikipedia.org/wiki/Ordinary_least_squares#Example_with_real_data example] on WP happens to be a polynomial regression example, and so code from the [[Polynomial regression]] task can be reused here. The only difference here is that givens x and y are computed in a separate function as a task prerequisite.
===Library gonum/matrix===
Line 2,424 ⟶ 2,409:
=={{header|Python}}==
{{libheader|NumPy}}
{{incorrect|Python|X input must be a two-dimensional array. Most examples on this page are wrong -- see task description and Talk.}}
 
'''Method with matrix operations'''
<syntaxhighlight lang="python">import numpy as np
Line 3,143 ⟶ 3,126:
{{trans|Kotlin}}
{{libheader|Wren-matrix}}
<syntaxhighlight lang="ecmascriptwren">import "./matrix" for Matrix
 
var multipleRegression = Fn.new { |y, x|
9,485

edits