<jupyter_start><jupyter_text>Linear Regression in R<jupyter_code>data1 = read.table('http://www.randomservices.org/random/data/Challenger2.txt',header = TRUE)
attach(data1) # to be able to use the labels
head(data1)
plot(T,I,col='darkblue',pch=8)
data1.lm = lm(I~T)
summary(data1.lm)
plot(T,I,col='darkblue',pch=8)
lines(T,fitted(data1.lm),col='brown',lwd=2)
# 95% posterior interval for the slope
-.24337 - 0.06349*qt(0.975,21)
-0.24337 + 0.06349*qt(.975,21)
# note that these are the same as the frequentist confidence intervals
# the Challenger launch was at 31 degrees Fahrenheit
# how much o-ring damage would we predict?
# y-hat

18.36508-0.24337*31
coef(data1.lm)
coef(data1.lm)[1] + coef(data1.lm)[2]*31  

# posterior prediction interval (same as frequentist)
predict(data1.lm,data.frame(T=31),interval="predict")  
10.82052-2.102*qt(.975,21)*sqrt(1+1/23+((31-mean(T))^2/22/var(T)))

# posterior probability that damage index is greater than zero
1-pt((0-10.82052)/(2.102*sqrt(1+1/23+((31-mean(T))^2/22/var(T)))),21)



#http://www.randomservices.org/random/data/Galton.txt
# Galton's seminal data on predicting the height of children from the 
# heights of the parents, all in inches

heights=read.table('http://www.randomservices.org/random/data/Galton.txt',header=T)
attach(heights)
names(heights)

pairs(heights,col='blue')


summary(lm(Height~Father+Mother+Gender+Kids))
summary(lm(Height~Father+Mother+Gender))
heights.lm=lm(Height~Father+Mother+Gender)

# each extra inch taller a father is is correlated with 0.4 inch extra
 # height in the child
# each extra inch taller a mother is is correlated with 0.3 inch extra
  #height in the child
# a male child is on average 5.2 inches taller than a female child
# 95% posterior interval for the the difference in height by gender
5.226 - 0.144*qt(.975,894)
5.226 + 0.144*qt(.975,894)

# posterior prediction interval (same as frequentist)
predict(heights.lm,data.frame(Father=68,Mother=64,Gender="M"),interval="predict")
predict(heights.lm,data.frame(Father=68,Mother=64,Gender="F"),interval="predict")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15083532219570406, 'fraction_numerical': 0.079236276849642, 'mean_word_length': 5.986666666666666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, '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': '394514', 'license': 'MIT', 'n_tokens_mistral': 874, 'n_tokens_neox': 759, 'n_words': 176, 'path': 'Linear Regression In R - Bayesian Statistics From Concept to Data Analysis.ipynb', 'repo_name': 'hodfa840/Bayesian-Statistics-Techniques-and-Models-In-Progress', 'size': '2095'}