-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrowthcurvesr.Rmd
180 lines (132 loc) · 6.11 KB
/
growthcurvesr.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
---
title: "Untitled"
author: "Nick Gembs"
date: "10/3/2022"
output:
word_document: default
html_document: default
---
```{r}
library("ggplot2")
```
```{r}
df = read.csv("C:/Users/Nick/Documents/GrowthCurve ALZ 131 Data Analysis Excel ng.csv")
```
```{r}
task1 = df[df[4] == 1,]
task2 = df[df[4] == 2,]
```
```{r}
lm.fit1 = lm(data = task1, correct ~ poly(CHILDAGE, degree=3, raw=T))
lm.fit2 = lm(data = task2, correct ~ poly(CHILDAGE, degree=3, raw=T))
summary(lm.fit1)
summary(lm.fit2)
```
```{r}
plot(task1$CHILDAGE, task1$correct, main = "Child correct vs Child Group for task 1: Cubic Overlay", xlab = "CHILD Group", ylab = "Correct Score", cex.main = .72)
lines(sort(task1$CHILDAGE), # Draw polynomial regression curve
fitted(lm.fit1)[order(task1$CHILDAGE)],
col = "red",
type = "l")
```
```{r}
plot(task2$CHILDAGE, task2$correct, main = "Child correct vs Child Group for task 2: Cubic Overlay", xlab = "CHILD Group", ylab = "Correct Score", cex.main = .72 )
lines(sort(task2$CHILDAGE), # Draw polynomial regression curve
fitted(lm.fit2)[order(task2$CHILDAGE)],
col = "red",
type = "l")
summary(lm.fit2)
f=expression( 0.248512 + -0.141121*x + 0.04712*x*x -0.002894*x*x*x)
exp = D(f,"x")
exp
exp1 = D(D(f,"x"),"x")
exp1
cc = function(x){0.248512 + -0.141121*x + 0.04712*x*x -0.002894*x*x*x}
b = function(x){-0.141121 + 2*.04712*x - 3* (.002894*x^2)}
curve(b, from=1, to=8, , main = "Derivative Plot for Task 2: Cubic Overlay", xlab = "CHILD Group", ylab = "Derivative", cex.main = 1, col = "red")
points(x = 939479318196729/173101855700000, y = b(939479318196729/173101855700000), pch = 19, cex = 1)
text(x = 939479318196729/173101855700000, y = b(939479318196729/173101855700000)-.02, labels = "Maximum: Group 5.42 ")
```
```{r}
ggp <- ggplot(task1, aes(CHILDAGE, correct), title = "Child correct vs Child Group for task 1: Cubic Overlay") + # Create ggplot2 scatterplot
geom_point()
ggp + # Add polynomial regression curve
stat_smooth(method = "lm",
formula = y ~ poly(x, 3),
se = TRUE)
ggp <- ggplot(task2, aes(CHILDAGE, correct)) + # Create ggplot2 scatterplot
geom_point()
ggp + # Add polynomial regression curve
stat_smooth(method = "lm",
formula = y ~ poly(x, 3),
se = TRUE)
```
```{r}
task1tr1 = task1[task1[7] == 1,]
task1tr2 = task1[task1[7] == 2,]
task1tr3 = task1[task1[7] == 3,]
task2tr1 = task2[task2[7] == 1,]
task2tr2 = task2[task2[7] == 2,]
task2tr3 = task2[task2[7] == 3,]
```
```{r}
lm.fit = lm(data = task1tr1, correct ~ poly(CHILDAGE, degree=3))
plot(task1tr1$CHILDAGE, task1tr1$correct, main = "Child correct vs Child Group for TASK1XTR1: Cubic Overlay", xlab = "CHILD Group", ylab = "Correct Score", cex.main = .72 )
lines(sort(task1tr1$CHILDAGE), # Draw polynomial regression curve
fitted(lm.fit)[order(task1tr1$CHILDAGE)],
col = "red",
type = "l")
lm.fit = lm(data = task1tr2, correct ~ poly(CHILDAGE, degree=3))
plot(task1tr2$CHILDAGE, task1tr2$correct, main = "Child correct vs Child Group for TASK1XTR2: Cubic Overlay", xlab = "CHILD Group", ylab = "Correct Score" , cex.main = .72)
lines(sort(task1tr2$CHILDAGE), # Draw polynomial regression curve
fitted(lm.fit)[order(task1tr2$CHILDAGE)],
col = "red",
type = "l")
lm.fit = lm(data = task1tr3, correct ~ poly(CHILDAGE, degree=3))
plot(task1tr3$CHILDAGE, task1tr3$correct, main = "Child correct vs Child Group for TASK1XTR3: Cubic Overlay", xlab = "CHILD Group", ylab = "Correct Score" , cex.main = .72)
lines(sort(task1tr3$CHILDAGE), # Draw polynomial regression curve
fitted(lm.fit)[order(task1tr3$CHILDAGE)],
col = "red",
type = "l")
lm.fit = lm(data = task2tr1, correct ~ poly(CHILDAGE, degree=3))
plot(task2tr1$CHILDAGE, task2tr1$correct, main = "Child correct vs Child Group for TASK2XTR1: Cubic Overlay", xlab = "CHILD Group", ylab = "Correct Score" , cex.main = .72)
lines(sort(task2tr1$CHILDAGE), # Draw polynomial regression curve
fitted(lm.fit)[order(task2tr1$CHILDAGE)],
col = "red",
type = "l")
lm.fit = lm(data = task2tr2, correct ~ poly(CHILDAGE, degree=3))
plot(task2tr2$CHILDAGE, task2tr2$correct, main = "Child correct vs Child Group for TASK2XTR2: Cubic Overlay", xlab = "CHILD Group", ylab = "Correct Score", cex.main = .72 )
lines(sort(task2tr2$CHILDAGE), # Draw polynomial regression curve
fitted(lm.fit)[order(task2tr2$CHILDAGE)],
col = "red",
type = "l")
lm.fit = lm(data = task2tr3, correct ~ poly(CHILDAGE, degree=3))
plot(task2tr3$CHILDAGE, task2tr3$correct, main = "Child correct vs Child Group for TASK2XTR3: Cubic Overlay", xlab = "CHILD Group", ylab = "Correct Score", cex.main = .72 )
lines(sort(task2tr3$CHILDAGE), # Draw polynomial regression curve
fitted(lm.fit)[order(task2tr3$CHILDAGE)],
col = "red",
type = "l")
```
```{r}
par(mar = c(5, 4, 4, 8))
plot(1:10)
```
```{r}
while (!is.null(dev.list())) dev.off()
par(mar=c(5, 4, 4, 8), xpd = TRUE)
lm.fit1 = lm(data = task1, correct ~ poly(CHILDAGE, degree=3))
lm.fit2 = lm(data = task2, correct ~ poly(CHILDAGE, degree=3))
plot(task1$CHILDAGE, task1$correct, main = "Child correct vs Child Group by TASK: Cubic Overlay", xlab = "CHILD Group", ylab = "Correct Score", cex.main = .72, col = "red", pch = 2)
lines(sort(task1$CHILDAGE), # Draw polynomial regression curve
fitted(lm.fit1)[order(task1$CHILDAGE)],
col = "red",
type = "l")
points(task2$CHILDAGE, task2$correct, xlab = "CHILD Group", ylab = "Correct Score", cex.main = .72,col = "blue" , pch = 6)
lines(sort(task2$CHILDAGE), # Draw polynomial regression curve
fitted(lm.fit2)[order(task2$CHILDAGE)],
col = "blue",
type = "l")
points(task1$CHILDAGE, task1$correct, main = "Child correct vs Child Group by TASK: Cubic Overlay", xlab = "CHILD Group", ylab = "Correct Score", cex.main = .72, col = "red", pch = 2)
legend(9,1, legend=c("Task 1", "Task 2"),
col=c("red", "blue"), lty = 1:1, cex=.9)
```