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

plot(diam~temp, data=snow)

lm.s<-lm(diam~temp, data=snow)
anova(lm.s)
# 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

summary(lm.s)
# 
# 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

plot(lm.s)

plot(diam~temp, data=snow)
pred<-predict(lm.s, 
  data.frame(temp=seq(-21, 0, 0.1)),
  se.fit=T)
lines(seq(-21, 0, 0.1), pred$fit)
lines(seq(-21, 0, 0.1), 
      pred$fit-2*pred$se.fit, lty=2)
lines(seq(-21, 0, 0.1), 
      pred$fit+2*pred$se.fit, lty=2)
qt(0.975, 12)


predict(lm.s, 
  data.frame(temp=5))

###Task 2
beer<-read.delim2("clipboard")
summary(beer)
plot(IQ~beer, data=beer)
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 

###Task3
seedl<-read.delim2("clipboard")
summary(seedl)
lm.full<-lm(seedlings~treatment+productivity+temperature,
            data=seedl)
anova(lm.full)
lm.0<-lm(seedlings~+1,
            data=seedl)
add1(lm.0, .~.+treatment+productivity+temperature,
     test="F")
lm.1<-update(lm.0, .~.+treatment)
add1(lm.1, .~.+treatment+productivity+temperature,
     test="F")
summary(lm.1)
plot(lm.1)
