Testiotsikko

library(caret)
## Loading required package: lattice
## Loading required package: ggplot2
iat <-c(47,32,21,36,54)
palkat <-c(18400,15600,11400,14800,21300)

#keskiarvot
mean(iat)
## [1] 38
mean(palkat)
## [1] 16300
#keskihajonnat otokselle
sd(iat)
## [1] 12.90349
sd(palkat)
## [1] 3746.999
#keskihajonnat perusjoukolle
sqrt(mean(iat^2)-mean(iat)^2)
## [1] 11.54123
sqrt(mean(palkat^2)-mean(palkat)^2)
## [1] 3351.418
cor (iat, palkat)
## [1] 0.9793306
lm1 <- lm (palkat ~ iat)
summary(lm1)
## 
## Call:
## lm(formula = palkat ~ iat)
## 
## Residuals:
##       1       2       3       4       5 
## -459.46 1006.31  -65.47 -931.23  449.85 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  5493.39    1346.74   4.079  0.02661 * 
## iat           284.38      33.91   8.386  0.00356 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 875.1 on 3 degrees of freedom
## Multiple R-squared:  0.9591, Adjusted R-squared:  0.9455 
## F-statistic: 70.33 on 1 and 3 DF,  p-value: 0.003556
lm1$coefficients
## (Intercept)         iat 
##   5493.3934    284.3844
paste('y=', coef(lm1)[[2]], 'x', '+', coef(lm1)[[1]])
## [1] "y= 284.384384384384 x + 5493.39339339339"
#hajontakaavio
plot(iat,palkat)
abline(lm(palkat ~ iat))

###Kuviot

x<- rnorm(100)
y<- x + rnorm(100, sd=0.5)
par(mar = c(5,4,1,1), las =1)
plot (x, y, main = "Minun simuloimani data")