So I have various sets of data and I used ggplot to plot the average of the sets of data and got the below plots.
It shows response time during a trial over the entire length of the trial. I would like to estimate an equation to fit these plots. I was going to export the data to excel and try to do it in there, but so far it's been a nightmare and I haven't been able to get it to work anywhere close to it.
Using the top left plot as an example, I think I was able to use the code below to get the following plot with a fit linear regression line on it. I also clipped the end of the data since I don't need data after 400s.
Hoever, when I get the coefficients using the last line in my code below, I get the following values.
I was expecting the y intercept to be around 0.53-0.55ish so when it gives me 0.79 I am sure I am doing something wrong, but not sure what.
I tried using ggpubr but kept getting errors as well so now I am stuck and hoping someone can help. Much appreciated!
{r}
library(dplyr)
library(dbplyr)
library(ggplot2)
library(ggpubr)
CL111 <- clDataCleaned %>%
select(partID, Layout, form, reliability, TS_LightOn, dur_cleaned) %>%
filter(Layout == "1" & form == "1" & reliability == "1")
#individual plot
ggplot(data = CL111) + geom_smooth(mapping = aes(x = TS_LightOn, y = dur_cleaned), method = "lm", se = FALSE, colour = "Green") +
labs(x = "TS Light On (Seconsd)", y = "TS Response Time (Seconds)", title = "Layout 1, Condition AO, INS High") +
theme(plot.title = element_text(hjust = 0.5)) +
stat_smooth(mapping = aes(x = TS_LightOn, y = dur_cleaned), method = "loess", se = TRUE) + xlim(0, 400) + ylim (0, 1.0)
#find coefficients for best fit line
lm(CL111$dur_cleaned ~ CL111$TS_LightOn)