Function Lines (error when used with fitted values of a truncated regression model)

#1
Hi everyone,

I'm having some trouble with the function lines() in R. Here is an example of the code:

<code>
x=rnorm(100)
y=10+2*x+pmax(x-0.5,0)+pmax(x-0.7,0)
model=lm(y~x+pmax(x-0.5,0)+pmax(x-0.7,0))
plot(x,model$fitted.values)
lines(x,model$fitted.values)
</code>

I want the function lines to draw a line through the datapoints. lines() does not seem to work here.. I can't use abline here, because I think it can only only straight lines
Anyone who knows what has gone wrong?

Thanks in advance,
Taibo
 
Last edited:

trinker

ggplot2orBust
#2
Re: Function Lines (error when used with fitted values of a truncated regression mode

I don't use base much but shouldn't you be using abline for this?
 
#3
Re: Function Lines (error when used with fitted values of a truncated regression mode

found the answer!
<code>
smoothingspline=smooth.spline(x,model$fitted.values)
plot(x,y)
lines(smoothingspline)
</code>
 

Dason

Ambassador to the humans
#4
Re: Function Lines (error when used with fitted values of a truncated regression mode

If you change your the angled brackets in <code> to square brackets [noparse]
Code:
[/noparse] then you'll get the correct formatting for the forum