Skip to content
Commit 55ecc70e authored by mitchelloharawild's avatar mitchelloharawild
Browse files

Fixed variable scoping for function parameters

```R
fit.poly.lm <- function(data, degree){
  trend <- 1:length(data)
  season <- factor(cycle(data))
  lm(data~poly(trend,degree) + season)
}
fit.poly.tslm <- function(data, degree){
  tslm(data~poly(trend,degree) + season)
}

fit.poly.lm(AirPassengers, 3)
fit.poly.tslm(AirPassengers, 3)
```
## lm()
Call:
lm(formula = data ~ poly(trend, degree) + season)

Coefficients:
         (Intercept)  poly(trend, degree)1  poly(trend, degree)2  poly(trend, degree)3               season2               season3  
             255.949              1326.834               132.348               -17.821                -9.283                23.336  
             season4               season5               season6               season7               season8               season9  
              17.690                19.862                57.104                94.164                91.294                39.992  
            season10              season11              season12  
               1.511               -34.902                -8.577  

## tslm()
Call:
tslm(formula = data ~ poly(trend, degree) + season)

Coefficients:
         (Intercept)  poly(trend, degree)1  poly(trend, degree)2  poly(trend, degree)3               season2               season3  
             255.949              1326.834               132.348               -17.821                -9.283                23.336  
             season4               season5               season6               season7               season8               season9  
              17.690                19.862                57.104                94.164                91.294                39.992  
            season10              season11              season12  
               1.511               -34.902                -8.577  
parent a03d4d44
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment