Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 0.66 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Extract the knots from a ns object
  2. library(splines)
  3. x <- runif(100000)
  4. spline <- ns(x, df=5)
  5.        
  6. > spline ['knots']
  7. [1] NA
  8.        
  9. > str(sp)
  10.  ns [1:117542, 1:5] 0.527 0.474 0.455 0.472 0.498 ...
  11.  - attr(*, "dimnames")=List of 2
  12.   ..$ : NULL
  13.   ..$ : chr [1:5] "1" "2" "3" "4" ...
  14.  - attr(*, "degree")= num 3
  15.  - attr(*, "knots")= Named num [1:4] 1.03 1.55 1.99 2.7
  16.   ..- attr(*, "names")= chr [1:4] "20%" "40%" "60%" "80%"
  17.  - attr(*, "Boundary.knots")= num [1:2] 0.0214 4.9999
  18.  - attr(*, "intercept")= logi FALSE
  19.  - attr(*, "class")= chr [1:3] "ns" "basis" "matrix"
  20.        
  21. > attr(spline, "knots")
  22.       20%       40%       60%       80%
  23. 0.1966951 0.3973261 0.5982386 0.7993613