tags:

views:

88

answers:

2

I read a R code on loess regression, here is part of it:

f.lo<- loess(bgs ~ f[,1], span=bw, degree=1)
bsln <- f.lo$fitted

What are their functions: bgs~f[,1] , the ~ and the $ in the next line? thanks

+1  A: 

Tilde ~ creates a formula, $ extracts the fitted element from S3 object (so de-facto list) created by loess. You can find more details in R-intro.

mbq
A: 

mbq's answer is correct, but I'll just add this:

> `~`(y, x)
y ~ x
> class(`~`(y, x))
[1] "formula"
> terms(`~`(y, x))
y ~ x
attr(,"variables")
list(y, x)
attr(,"factors")
  x
y 0
x 1
attr(,"term.labels")
[1] "x"
attr(,"order")
[1] 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
> 
Vince