Bonjour,
je suis un peu coincé.
Je travaille sous le logiciel R ( http://www.r-project.org/ )
Et je voudrais utiliser une fonction qui permet de lisser un signal : supsmu.
Le code de cette fonction est celui-ci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function (x, y, wt = rep(1, n), span = "cv", periodic = FALSE, 
    bass = 0) 
{
    if (span == "cv") 
        span <- 0
    n <- length(y)
    if (!n || !is.numeric(y)) 
        stop("'y' must be numeric vector")
    if (length(x) != n) 
        stop("number of observations in 'x' and 'y' must match.")
    if (length(wt) != n) 
        stop("number of weights must match number of observations.")
    if (span < 0 || span > 1) 
        stop("'span' must be between 0 and 1.")
    if (periodic) {
        iper <- 2
        xrange <- range(x)
        if (xrange[1] < 0 || xrange[2] > 1) 
            stop("'x' must be between 0 and 1 for periodic smooth")
    }
    else iper <- 1
    okay <- is.finite(x + y + wt)
    ord <- order(x[okay], y[okay])
    ord <- cumsum(!okay)[okay][ord] + ord
    xo <- x[ord]
    leno <- length(ord)
    if (leno == 0) 
        stop("no finite observations")
    if (diff <- n - leno) 
        warning(diff, " observation(s) with NAs, NaNs and/or Infs deleted")
    .Fortran(R_setsmu)
    smo <- .Fortran(R_supsmu, as.integer(leno), as.double(xo), 
        as.double(y[ord]), as.double(wt[ord]), as.integer(iper), 
        as.double(span), as.double(bass), smo = double(leno), 
        double(n * 7), double(1))$smo
    dupx <- duplicated(xo)
    list(x = xo[!dupx], y = smo[!dupx])
}
Ce que fait cette fonction est là :
Friedman's SuperSmoother
Description
Smooth the (x, y) values by Friedman's ‘super smoother’.

Usage
supsmu(x, y, wt, span = "cv", periodic = FALSE, bass = 0)

Arguments
x x values for smoothing
y y values for smoothing
wt case weights, by default all equal
span the fraction of the observations in the span of the running lines smoother, or "cv" to choose this by leave-one-out cross-validation.
periodic if TRUE, the x values are assumed to be in [0, 1] and of period 1.
bass controls the smoothness of the fitted curve. Values of up to 10 indicate increasing smoothness.

Details
supsmu is a running lines smoother which chooses between three spans for the lines. The running lines smoothers are symmetric, with k/2 data points each side of the predicted point, and values of k as 0.5 * n, 0.2 * n and 0.05 * n, where n is the number of data points. If span is specified, a single smoother with span span * n is used.

The best of the three smoothers is chosen by cross-validation for each prediction. The best spans are then smoothed by a running lines smoother and the final prediction chosen by linear interpolation.

The FORTRAN code says: “For small samples (n < 40) or if there are substantial serial correlations between observations close in x-value, then a pre-specified fixed span smoother (span > 0) should be used. Reasonable span values are 0.2 to 0.4.”

Cases with non-finite values of x, y or wt are dropped, with a warning.

Value
A list with components

x the input values in increasing order with duplicates removed.
y the corresponding y values on the fitted curve.

References
Friedman, J. H. (1984) SMART User's Guide. Laboratory for Computational Statistics, Stanford University Technical Report No. 1.

Friedman, J. H. (1984) A variable span scatterplot smoother. Laboratory for Computational Statistics, Stanford University Technical Report No. 5.

See Also
ppr

Examples
require(graphics)

with(cars, {
plot(speed, dist)
lines(supsmu(speed, dist))
lines(supsmu(speed, dist, bass = 7), lty = 2)
})
Ce que je ne comprend pas, c'est : pourquoi il faut une seconde variable d'entrée "y"? Il n'y a qu'un seul signal à lisser, et les paramètres de lissage sont sur les autres variable "bass", "span", ...)

Si quelqu'un pouvait m'éclairer se serait agréable.

Merci