<jupyter_start><jupyter_text>Aufgabe 22<jupyter_code>x = c(1,2,3,4)
y = c(1.2, 1.3, 3.5, 3)
x
y
model = lm(y ~ x)
model
x.beta = x*coef(model)
epsilon = y - x.beta
print("results:")
print("Beta:")
print(coef(model))
print("epsilon")
print(epsilon)
print("y") 
print(x.beta + epsilon)
all(x.beta + epsilon == y)

model.b = lm(x ~ y)
x.beta = x*coef(model.b)
epsilon = y - x.beta

print("results:")
print("Beta:")
print(coef(model.b))
print("epsilon")
print(epsilon)
print("y") 
print(x.beta + epsilon)
all(x.beta + epsilon == y)

plot(y~x)
abline(model, col="red")
abline((coef(model.b)), col="blue")
install.packages("gamair")
library(gamair)
data(hubble)
hubble
plt = plot(hubble$y ~ hubble$x)
lsq = lm(hubble$y~hubble$x+0)
# Formula: coef(lsq) x + 0, in Hz
abline(lsq)
points = identify(x=hubble$x, y=hubble$y)

# beta = 1/s
lsq.less = lm(hubble$y[-c(3,15)]~hubble$x[-c(3,15)]+0)
abline(lsq.less, col="red")

dist = function(point, line) {
    
}

age.1 = 1/(coef(lsq)) * 3.09*10^19 / 60 / 60 / 24 / 365
age.2 = 1/(coef(lsq.less)) * 3.09*10^19 / 60 / 60 / 24 / 365

age.1 # 12.8 billion
age.2 # 12.6 billion
abs(age.1- age.2)  #~17 million years difference<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21717171717171718, 'fraction_numerical': 0.05976430976430976, 'mean_word_length': 4.6084905660377355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '361551', 'license': 'MIT', 'n_tokens_mistral': 611, 'n_tokens_neox': 562, 'n_words': 108, 'path': 'statistics/Blatt8/Blatt8.ipynb', 'repo_name': 'RunOrVeith/algorithm-tests', 'size': '1188'}