### Task 1
snow<-read.delim2("clipboard")
summary(snow)

lm.1<-lm(diam~temp, data=snow)
plot(lm.1)
anova(lm.1)
# Analysis of Variance Table
# 
# Response: diam
#           Df Sum Sq Mean Sq F value    Pr(>F)    
# temp       1 32.798  32.798  89.111 6.652e-07 ***
# Residuals 12  4.417   0.368                      
# ---
# Signif. codes:  
# 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

summary(lm.1)
# Call:
# lm(formula = diam ~ temp, data = snow)
# 
# Residuals:
#      Min       1Q   Median       3Q      Max 
# -1.05721 -0.21684  0.07169  0.17846  1.12766 
# 
# Coefficients:
#             Estimate Std. Error t value Pr(>|t|)    
# (Intercept) 10.65537    0.31037   34.33 2.37e-13 ***
# temp         0.26101    0.02765    9.44 6.65e-07 ***
# ---
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# 
# Residual standard error: 0.6067 on 12 degrees of freedom
# Multiple R-squared:  0.8813,	Adjusted R-squared:  0.8714 
# F-statistic: 89.11 on 1 and 12 DF,  p-value: 6.652e-07

library(ggplot2)
ggplot(data=snow, aes(x=temp, y=diam))+geom_point()+
  geom_smooth(method="lm", colour=1)+
  labs(x="Ice temperature", y="Snowflake diameter")+
  theme_classic()

coef(lm.1)
# (Intercept)        temp 
#  10.6553709   0.2610089

predict(lm.1, newdata = list(temp=5))
#        1 
# 11.96042 
## This prediction is however non-sense because ice temperature 
##cannot exceed 0. Beware that it is an extrapolation here.


### Task 2
beer<-read.delim2("clipboard")


cor.test(beer$IQ, beer$beer)
# 	Pearson's product-moment correlation
# 
# data:  beer$IQ and beer$beer
# t = -0.51757, df = 10, p-value = 0.616
# alternative hypothesis: true correlation is not equal to 0
# 95 percent confidence interval:
#  -0.6730350  0.4545116
# sample estimates:
#        cor 
# -0.1615223 

lm.2<-lm(beer$IQ~beer$beer)
summary(lm.2)
# Call:
# lm(formula = beer$IQ ~ beer$beer)
# 
# Residuals:
#     Min      1Q  Median      3Q     Max 
# -22.296  -8.731   1.298   7.811  24.291 
# 
# Coefficients:
#             Estimate Std. Error t value Pr(>|t|)    
# (Intercept)  93.1578     7.0799  13.158 1.22e-07 ***
# beer$beer    -0.9311     1.7991  -0.518    0.616    
# ---
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# 
# Residual standard error: 15.62 on 10 degrees of freedom
# Multiple R-squared:  0.02609,	Adjusted R-squared:  -0.0713 
# F-statistic: 0.2679 on 1 and 10 DF,  p-value: 0.616

ggplot(beer, aes(x=beer, y=IQ))+geom_point()+theme_classic()

