My results of using splines::ns with a subset of the least squares changed without the rhyme or reason I could see, and I think I traced this problem to the ns function itself.
I solved the problem:
require(splines) N <- 0 set.seed(1) for (i in 1:100) N <- N + identical(ns(1:10,3),ns(1:10,3)) N
My results averaged around 39, range 34--44 or so, but I expected 100 every time. Why should ns results be random? If I replace bs with ns in both places, I will get 100, as expected. My set.seed(1) hoping to demonstrate that the randomness I get is not what R. intended.
In a clean session, using RStudio and R version 2.14.2 (2012-02-29), I get 39, 44, 38, etc. Everyone else seems to get 100.
Additional Information:
Substituting splines::ns for ns gives the same results. A pure vanilla session gives the same results. My computer has 8 cores.
The differences when they occur are usually or always 2 ^ -54:
Max <- 0 for (i in 1:1000) Max <- max( Max, abs(ns(1:10,3)-ns(1:10,3)) ) c(Max,2^-54)
with the result of [1] 5.551115e-17 5.551115e-17 . This variability causes me big problems along the line, because my optimize(...)$min now sometimes changes even in the first digit, making the results not repeatable.
My InfoInfo with a clean vanilla session:
I created what I understand is called a pure vanilla session using
> .Last <- function() system("R --vanilla") > q("no")
This resets the session, and when I restart it, I get my pure vanilla session. Then, in response to a question from Ben Bolker, I did this at the beginning of my clean vanilla session:
> sessionInfo() R version 2.14.2 (2012-02-29) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] Revobase_6.1.0 RevoMods_6.1.0 RevoScaleR_3.1-0 lattice_0.20-0 [5] rpart_3.1-51 loaded via a namespace (and not attached): [1] codetools_0.2-8 foreach_1.4.0 grid_2.14.2 iterators_1.0.6 [5] pkgXMLBuilder_1.0 revoIpe_1.0 tools_2.14.2 XML_3.9-1.1 > require(splines) Loading required package: splines > N <- 0 > set.seed(1) > for (i in 1:100) N <- N + identical(ns(1:10,3),ns(1:10,3)) > N [1] 32