-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.Rmd
69 lines (57 loc) · 1.36 KB
/
stats.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
output:
github_document:
html_preview: false
toc: true
toc_depth: 2
---
<!-- stats.md is generated from stats.Rmd Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
options(tibble.print_min = 5, tibble.print_max = 5)
```
#### ANOVA
[video source](https://www.youtube.com/watch?v=fT2No3Io72g)
```{r eval=FALSE}
Group1 <- c(2,3,7,2,6)
Group2 <- c(10,8,7,5,10)
Group3 <- c(10,13,14,13,15)
Combined_Groups <- data.frame(cbind(Group1, Group2, Group3))
Stacked_Groups <- stack(Combined_Groups)
Anova_Results <- aov(values ~ ind, data = Stacked_Groups)
summary(Anova_Results)
```
#### Line and curve fitting
Fit a line to series of points
```{r eval=FALSE}
#data
m <- 5
n <- 2
input <- matrix(c(1, 6, 2, 5, 3, 7, 4, 10, 5, 14), ncol = n, byrow = T)
k <- rep(1,m)
X <- cbind(k, input[,1])
y <- input[,2]
X.T <- t(X)
betaHat <- solve(X.T%*%X) %*% X.T %*%y
print(betaHat)
plot(input)
abline(betaHat[1], betaHat[2])
```
Fit a 2nd degree polynomial to series of points
```{r eval=FALSE}
X <- cbind(rep(1,m), input[,1], (input[,1])^2)
y <- input[,2]
X.T <- t(X)
betaHat <- solve(X.T%*%X) %*% X.T %*%y
print(betaHat)
plot(input)
#plot curve beyond original data
num_points <- 10
new_X <- c(1:num_points)
new_poly <- cbind(rep(1,num_points),new_X,new_X^2)
plot(x = new_X, y = new_poly%*%betaHat,col='red')
lines(input)
```