I'm a beginner to R and I'm trying to fit a curve onto a data set that (for example) might look like the below:
(x- value) (y-value)
105 423
115 471
125 567
135 808
145 921.5
155 1040
The x value's represent the amount of stimulus and the y values represent motor responses (in uV). These are averages over 10 subjects, where the x-values are the same for each subject.
I was told that this data set normally follows a sigmoidal fit. I tried fitting it with the following:
fit <- lm( y ~ poly(x, 3) )
But I'm not sure if this is the appropriate way to do this :(
My code looks like this so far:
p <- ggplot (data, aes(x, y)) +
geom_point(shape= 21, fill= "blue", colour= "black", size=2) +
xlab("X value") + ylab("Y value") +
geom_smooth(method= "lm", se= FALSE, colour= "red", formula=y ~ poly(x, 3, raw=TRUE)) +
geom_errorbar(aes(ymin=y-SE, ymax=y+SE), width=.9)+
ggtitle ("Title")
p
Additionally: Once I fit the the curve I would also like to obtain the slope (calculated as the value of the tangent at the steepest point of the curve)
Thanks in advance, any help would be greatly appreciated!