
# MODIFY THE BELOW FOR ABOVE POLYNOMIAL EG TAKEN FROM
# https://www.statology.org/plot-predicted-values-in-r/
#plot predicted vs. actual values
#plot(x=predict(model), y=df$y,
#     xlab='Predicted Values',
#    ylab='Actual Values',
#    main='Predicted vs. Actual Values')

# two ways to plot orthogonal polynomials (quadratic)
# can estimate turning point by differentation = -B/2A for Ax^2 + Bx + C=0

library(stats)
y=read.table("U://My Documents//norm.dat",header=F)
y <- data.frame(y)
attach(y)
yy <- replace(y,y==999,NA)
#yy2 <- yy[yy$V1==301,]
#p301 <- lm(yy2$V12 ~ yy2$V14+yy2$V14^2)
#p301$fitted.values
#plot(yy2$V14,yy2$V12)
#abline(p301,lty=3)
yy2 <- yy[yy$V1==301,]
orth_poly <- poly(yy2$V14, degree=2)
p301 <- lm(yy2$V12 ~ orth_poly)
p301$fitted.values
plot(yy2$V14,yy2$V12)
points(c(1:20),p301$fitted.values,pch=2)
lines(c(1:20),p301$fitted.values,lty=2)

p301 <- lm(yy2$V12 ~ yy2$V14 + I(yy2$V14^2))
p301$fitted.values
plot(yy2$V14,yy2$V12, main="Fluency change over time", xlab="Occasion", ylab="S Fluency")
axis(1, at=c(1:20))
axis(2, at=c(15,20,25,30,35,40,45,50))
points(c(1:20),p301$fitted.values,pch=2)
lines(c(1:20),p301$fitted.values,lty=2)

p301 <- lm(yy2$V12 ~ yy2$V14 + I(yy2$V14^2))
p301$fitted.values
plot(yy2$V14,yy2$V12, main="Fluency change over time", xlab="Occasion", ylab="S Fluency")
axis(1, at=c(1:20))
axis(2, at=c(15,20,25,30,35,40,45,50))
points(c(1:20),p301$fitted.values,pch=2)
lines(c(1:20),p301$fitted.values,lty=2)




