Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201977

Plotting estimated polynomials in R using lines() and predict()

$
0
0

I'm somewhat of a rookie, but trying to plot 6 parameter values against 6 means. I have this code:

meanGdEV = c(-0.74085561, -0.50071115, -0.29904040, 0.05227249, 0.43114683, 0.83719626)
modelGdEVv3$par[4:9] = c(3.145259, 2.247203, 2.088391, 2.274646, 2.239679, 1.870732)

model.linear <- lm(modelGAv3$par[4:9] ~ meanGdEV)
model.squared <- lm(modelGAv3$par[4:9] ~ poly(meanGdEV,3))
anova(model.linear,model.squared)

plot(meanGdEV, modelGdEVv3$par[4:9], type = "p", col = 1, pch=1, xlim = c(-1,1), ylim = c(-3, 3), xlab = "binmeans", ylab = "driftrate parameter values (v)")
abline(model.linear)
lines(meanGdEV, predict(model.squared, newdata = as.data.frame(meanGdEV)))

The problem is, when plotting it seems to only use the first 2 estimated parameter values. If I change the 3 in poly(meanGdEV,3) to a different number, nothing changes, except for the values 1 and 2.

This is the plot I get with the code above

as requested, model.linear$coefficients and model.squared$coefficients:

(Intercept)     meanGdEV 
 2.133396100 -0.009754665 

(Intercept) poly(meanGdEV, 3)1 poly(meanGdEV, 3)2 poly(meanGdEV, 3)3 
2.13375376        -0.01297941        -0.74482721         0.08564994 

I hope you guys can help!


Viewing all articles
Browse latest Browse all 201977

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>