Question

I'd like to predict a y with several x values (x1, x2, x3, x4, x5, x6). A linear model is very simple, but i don't understand how can i use loess.smooth, smooth.splines and sm.regression with more x variables. I tried using a dataset or a matrix as x, but this way doesn't work.

x is a matrix 700x6, while y is a 700 element array.

sm1=sm.regression(x, y, h=0.5, add=F, ngrid=300, display="none")

Error in sm.check.data(x = x, y = y, weights = weights, group = group, : x has too many columns

ls1=loess.smooth(x, y, span=0.5)

simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE, : NA/NaN/Inf in foreign function call (arg 1)

I checked and there aren't any NA, Nan or Inf in x.

ss1=smooth.spline(x,y, spar=0.5)

Error in xy.coords(x, y) : 'x' and 'y' lengths differ

Was it helpful?

Solution

Those functions are simpler and designed for a pair of x and y variables. Suitable alternatives exist, such as in the forms of two functions named gam(), one in package mgcv which comes with R as a Recommended package, and the other in package gam which is an R version of the GAM software (gam()) in S-PLUS and the original implementation following Hastie & Tibshirani's "mono"graph on Generalised Additive Models (GAM).

Both fit so called additive models where the main assumption is that the terms in the model contribute in additively to the give the fitted response. If you want LOESS-based smooths in the GAM, try package gam, but mgcv has a wider range of penalised regression splines and has a more modern approach to smoothness selection in the individual splines.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top