O'Reilly logo

R Statistical Application Development by Example Beginner's Guide by Prabhanjan Narayanachar Tattar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – fitting the spline regression models

A natural cubic spline regression model will be fitted for the voltage drop problem.

  1. Read the required dataset into R by using data(VD).
  2. Invoke the graphics editor by using par(mfrow=c(1,2)).
  3. Plot the data and give an appropriate title:
    plot(VD)
    title(main="Scatter Plot for the Voltage Drop")
  4. Build the piecewise cubic polynomial regression model by using the lm function and related options:
    VD_PRS<-lm(Voltage_Drop~Time+I(Time^2)+I(Time^3)+I(((Time-6.5)^3)*(sign(Time-6.5)==1))+I(((Time-13)^3)*(sign(Time-13)==1)),data=VD)

    The sign function returns the sign of a numeric vector as 1, 0, and -1, accordingly as the arguments are positive, zero, and negative respectively. The operator I is an inhibit interpretator ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required