This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
beta_hat_1 = sigma_xy / sigma2_x | |
beta_hat_0 = y_bar - beta_hat_1*x_bar | |
Y_hat = beta_hat_0 + beta_hat_1*X | |
sigma2_y_hat = ((Y_hat - y_bar)**2).sum()/Y.size | |
R2 = sigma2_y_hat / sigma2_y | |
r2 = r**2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sigma2_x = ((X - x_bar)**2).sum()/X.size | |
sigma2_y = ((Y - y_bar)**2).sum()/Y.size | |
sigma_x = np.sqrt(sigma2_x) | |
sigma_y = np.sqrt(sigma2_y) | |
sigma_xy = (X*Y).sum()/X.size - x_bar*y_bar | |
r = sigma_xy / (sigma_x*sigma_y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x_bar = X.sum()/X.size | |
y_bar = Y.sum()/Y.size | |
fig, ax = plt.subplots(facecolor="w") | |
plt.plot(X, Y, "o", label="observations") | |
plt.axvline(x_bar, ls="--", label=fr"$\bar{{x}}={x_bar:.2f}$", color="C1") | |
plt.axhline(y_bar, ls="--", label=fr"$\bar{{y}}={y_bar:.2f}$", color="C2") | |
plt.legend(loc="upper left", bbox_to_anchor=(1,1)) | |
plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
X = np.arange(20).astype(float) | |
Y = X*2 | |
X += np.random.random(size=X.size)*5 | |
Y += np.random.random()*5 | |
plt.plot(X, Y, "o", label="observations") | |
plt.legend(loc="upper left", bbox_to_anchor=(1,1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy.stats as sps | |
import matplotlib.pyplot as plt | |
tau = 5 | |
beta = 1/tau | |
alpha = 5 | |
t = 15 | |
lam = beta*t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy.stats as sps | |
import matplotlib.pyplot as plt | |
tau = 5 | |
beta = 1/tau | |
alpha = 5 | |
t = 15 | |
lam = beta*t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy.stats as sps | |
import matplotlib.pyplot as plt | |
tau = 5 | |
beta = 1/tau | |
alpha = 5 | |
d = sps.gamma(a=alpha, scale=1/beta) | |
x = np.linspace(0, d.ppf(.999), 1000) | |
y = d.pdf(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy.stats as sps | |
import matplotlib.pyplot as plt | |
tau = 5 | |
beta = 1/tau | |
d = sps.expon(scale=1/beta) | |
x = np.linspace(0, d.ppf(.999), 1000) | |
y = d.pdf(x) | |
P = d.cdf(15) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Zn variable from Yn | |
Zn2 = (Yn - d.mean()) / (d.std()/np.sqrt(n)) | |
# Standard Normal distribution of Zn | |
plt.hist(Zn2, density=True) | |
Znd = sps.norm(loc=0, scale=1) | |
Znx = np.linspace(Znd.ppf(.0001), Znd.ppf(.9999), 100) | |
Zny = Znd.pdf(Znx) | |
plt.plot(Znx, Zny, lw=5) | |
plt.title("Distribution of r.v. $Z_n$ from $Y_n$") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Zn variable from Sn | |
Zn1 = (Sn - n*d.mean()) / (np.sqrt(n)*d.std()) | |
# Standard Normal distribution of Zn | |
plt.hist(Zn1, density=True) | |
Znd = sps.norm(loc=0, scale=1) | |
Znx = np.linspace(Znd.ppf(.0001), Znd.ppf(.9999), 100) | |
Zny = Znd.pdf(Znx) | |
plt.plot(Znx, Zny, lw=5) | |
plt.title("Distribution of r.v. $Z_n$ from $S_n$") |
NewerOlder