0

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

As As
  • 2,049
  • 4
  • 17
  • 33
  • The first two won't work I don't think. From `sm.regression` docs: x is a vector, or two-column matrix, of covariate values. `loess.smooth` is for producing plots from a smoother. Again from the docs: Plot and add a smooth curve computed by loess to a scatter plot. I'm not sure about `smooth.spline`. It would help to see a sample of your data set (e.g. `dput(head(data))`. – matt_k Mar 29 '14 at 22:36
  • You maybe need to get your strategy straight first, and if you expect help on SO you should post a data example. There are many regression approaches that support prediction with splines or locally estimated surfaces, but SO asks you to have thrashed out those details before posting. Perhaps CrossValidated.com could help if you described in more detail what you need rather than describing what doesn't work. – IRTFM Mar 29 '14 at 23:19

1 Answers1

0

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.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453