[R] Trouble with line of best fit

Daniel Malter daniel at umd.edu
Mon Jul 25 21:31:38 CEST 2011


Hi,

I hope this is for private purposes. Otherwise, I may cite David Winsemius:
"The advancement of science would be safer if you knew what you were doing."

First, your regression command is inverted. You ought to regress SoloKills
on range, not vice versa.

abline(lm(graph~range)) #does the trick

Second, given the figure, a linear specification is obviously a
misspecification of your model, unless you account for autocorrelation.

pacf(reg$res,plot=T)

HTH,
Daniel




DimmestLemming wrote:
> 
> I don't usually do much with graphs in R, and this is my first time adding
> a line of best fit. Hopefully this is an easy problem to solve.
> 
> I'm looking at a variable called soloKills along the range 5:28. Here are
> all my commands, in script form:
> 
> range=5:28
> graph=soloKills
> title="Solo kill/death data"
> xlabel="Number of deaths/1 game"
> ylabel="Mean number of kills/1 game"     #No problems with the scatterplot
> 
> plot(x=range, y=graph, main=title, xlab=xlabel, ylab=ylabel, ylim=c(0,20))
> 
> abline(lm(range~graph))
> 
> I checked several websites, the abline(lm(/x-variable/~/y-variable/))
> format *should* work. But here is what happens:
> 
>  http://r.789695.n4.nabble.com/file/n3693567/Regression_problem.png 
> 
> The line is obviously far too steep. I can guarantee there are no outliers
> in soloKills to throw it off:
> 
>> soloKills
>  [1]  9.040472 10.184595 11.201935 12.130823 13.583477 14.098845 14.489703
>  [8] 15.329752 15.562500 15.884757 16.239704 16.513289 16.383912 16.547543
> [15] 16.823374 17.051370 17.027644 17.300562 17.641723 17.702673 18.436170
> [22] 18.783562 19.274419 21.373832
> 
> Can anyone help me fix the regression line? Thanks!
> 

--
View this message in context: http://r.789695.n4.nabble.com/Trouble-with-line-of-best-fit-tp3693567p3693745.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list