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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.