How to do it...

We will generate synthetic data, first a fully linear model where each independent variable (two of them) will have a linear impact. Secondly, a model with one variable:

  1. First, we generate some data for regression. The relationship will be linear and there is nothing new up to this point, as shown in the following example:
library(SemiPar)x1 = rnorm(100,20,6)x2 = runif(100,1,8)y = x1 + x2 + rnorm(100,0,5)data_sim = data.frame(x1=x1,x2=x2,y=y)
  1. Next, we set up our semiparametric model, and we assume that there is an additive relationship between the variables. Because we generated the data, we already know that no transformation of the variables is necessary. But let's assume we didn't know this, and specify a general f() ...

Get R Statistics Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.