Skip to content

Instantly share code, notes, and snippets.

@tautologico
Created July 8, 2013 17:11
Show Gist options
  • Save tautologico/5950645 to your computer and use it in GitHub Desktop.
Save tautologico/5950645 to your computer and use it in GitHub Desktop.
Simple linear regression
using DataFrames
datafile = "data1.csv"
function coeff(data::AbstractDataFrame)
n = nrow(data)
A = sum(data["pop"])
Y = sum(data["profit"])
ya = sum(data["pop"] .* data["profit"])
a2 = sum(data["pop"] .^ 2)
k = (n * ya - Y * A) / (n * a2 - A^2)
c = (Y - k * A) / n
(k, c)
end
if !isinteractive()
data1 = readtable(datafile)
k, c = coeff(data1)
println "Coeficientes: k = $k, c = $c"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment