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

#### Taibo

##### New Member
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?

Taibo

Last edited:

#### trinker

##### ggplot2orBust
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?

#### Taibo

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

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

#### Dason

[/noparse] then you'll get the correct formatting for the forum