Skip to content

Commit

Permalink
Merge pull request #205 from gabriel-fallen/source
Browse files Browse the repository at this point in the history
Julia implementation of the Simple Linear Regression
  • Loading branch information
grantmcdermott authored Oct 3, 2023
2 parents 95fbb84 + 42596c0 commit bf59d3c
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions Model_Estimation/OLS/simple_linear_regression.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ For more information about OLS, see [Wikipedia: Ordinary Least Squares](https://

- OLS assumes that you have specified a true linear relationship.
- OLS results are not guaranteed to have a causal interpretation. Just because OLS estimates a positive relationship between $$X_1$$ and $$Y$$ does not necessarily mean that an increase in $$X_1$$ will cause $$Y$$ to increase.
- OLS does *not* require that your variables follow a normal distribution.
- OLS does *not* require that your variables follow a normal distribution.

## Also Consider

Expand All @@ -40,6 +40,31 @@ open https://github.com/LOST-STATS/lost-stats.github.io/blob/master/Data/auto.gd
ols mpg const headroom trunk weight
```

## Julia

```julia
# Uncomment the next line to install all the necessary packages
# import Pkg; Pkg.add(["CSV", "DataFrames", "GLM", "StatsModels"])

# We tap into JuliaStats ecosystem to solve our data and regression problems :)
# In particular, DataFrames package provides dataset handling functions,
# StatsModels gives us the `@formula` macro to specify our model in a concise and readable form,
# while GLM implements (Generalized) Linear Models fitting and analysis.
# And all these packages work together seamlessly.
using StatsModels, GLM, DataFrames, CSV

# Here we download the data set, parse the file with CSV and load into a DataFrame
mtcars = CSV.read(download("https://github.com/LOST-STATS/lost-stats.github.io/raw/source/Data/mtcars.csv"), DataFrame)

# The following line closely follows the R and Python syntax, thanks to GLM and StatModels packages
# Here we specify a linear model and fit it to our data set in one go
ols = lm(@formula(mpg ~ cyl + hp + wt), mtcars)

# This will print out the summary of the fitted model including
# coefficients' estimates, standard errors, confidence intervals and p-values
print(ols)
```

## Matlab

```matlab
Expand Down Expand Up @@ -93,13 +118,13 @@ summary(olsmodel)

```sas
/* Load Data */
proc import datafile="C:mtcars.dbf"
proc import datafile="C:mtcars.dbf"
out=fromr dbms=dbf;
run;
/* OLS regression */
proc reg;
model mpg = cyl hp wt;
run;
run;
```

## Stata
Expand Down

0 comments on commit bf59d3c

Please sign in to comment.