search for: knots

Displaying 20 results from an estimated 348 matches for "knots".

Did you mean: knobs
2013 Jan 28
2
Why are the number of coefficients varying? [mgcv][gam]
...e some of it is predicted when missing). In MI, coefficients from multiple models are averaged, as are variance-covariance matrices. VCV's get an additional correction to account for how variable they are between each other. For this to work in the context of a penalized spline model, the knots need to be specified identically for each model (this is assisted by context knowledge), and each model needs to have the same number of knots. This is what I've done, below. I run that code multiple times with slightly different (imputed) datasets, but the number of coefficients varies...
2013 May 21
1
making makepredictcall() work
...on similar to ns() from package splines that can be passed in a model formula. The idea is to produce "safe" predictions from a model using this function. As I have seen, to do this I need to use makepredictcall(). Consider the following toy example: myns <- function (x, df = NULL, knots = NULL, intercept = FALSE, Boundary.knots = range(x), extraArg = 0) { ns.x <- if (is.null(knots)) { ns(x, df = df, intercept = intercept, Boundary.knots = Boundary.knots) } else { ns(x, knots = knots, intercept = intercept, Boundary.knots = Boun...
2010 Jun 11
1
Documentation of B-spline function
Goodmorning, This is a documentation related question about the B-spline function in R. In the help file it is stated that: "df degrees of freedom; one can specify df rather than knots; bs() then chooses df-degree-1 knots at suitable quantiles of x (which will ignore missing values)." So if one were to specify a spline with 6 degrees of freedom (and no intercept) then a basis with 6-3-1 =2 internal knots should be created. However this is not what happens: > library(...
2011 Jun 08
1
predict with model (rms package)
...r workspace which does not contain the vector of knot locations, I get an error message if I try to predict with that model. This also happens if only one workspace is used, but the vector of knot locations is removed: library(rms) set.seed(1) x <- rnorm(100) y <- 1 + x + x^2 + rnorm(100) x.knots <- quantile(x, c(0.2, 0.5, 0.8)) ols1 <- ols(y ~ rcs(x, x.knots)) predict(ols1, data.frame(x = 0)) # This works rm(x.knots) predict(ols1, data.frame(x = 0)) # Gives error The first predict gives 1 0.8340293 while the second predict gives Error in rcs(x, x.knots) : object 'x.k...
2024 Jul 08
0
package spline - default value of Boundary.knots of ns
...guments to reproduce the results. The package documentation also couldn't help me find the problem. Finally, I found a stack exchange question (https://stats.stackexchange.com/questions/588769/natural-splines-in-r-with-ns)? which helped me understand the problem - the default values of boundary knots are not useful. The problem is described in the stack exchange question, which I request you to kindly read. My suggestion is to change the default value of the argument Boundary.knots to NULL and calculate its values from? the extreme values of the argument knots inside the function body if it i...
2012 Nov 29
1
[mgcv][gam] Manually defining my own knots?
Dear List, I'm using GAMs in a multiple imputation project, and I want to be able to combine the parameter estimates and covariance matrices from each completed dataset's fitted model in the end. In order to do this, I need the knots to be uniform for each model with partially-imputed data. I want to specify these knots based on the quantiles of the unique values of the non-missing original data, ignoring the NA's. When I fit the GAM with the imputed data included, I don't want mgcv to use the data that it is supp...
2016 Apr 22
0
R2BayesX help
...se<-0.2 eta<-f2(x1.tot,x2.tot,x3.tot,x4.tot) y.tot<-eta+pnoise*rnorm(nsample,0,1) d<-data.frame(y.tot,x1.tot,x2.tot,x3.tot,x4.tot,x5.tot,x6.tot,x7.tot) nk2<-5 # the full model that contains the interactions of all pairs of x1~x7, 21 terms in total fr2<-y.tot ~ sx(x1.tot, x2.tot, knots = nk2, bs = "te") + sx(x1.tot, x3.tot, knots = nk2, bs = "te") + sx(x1.tot, x4.tot, knots = nk2, bs = "te") + sx(x1.tot, x5.tot, knots = nk2, bs = "te") + sx(x1.tot, x6.tot, knots = nk2, bs = "te") + sx(x1.tot, x7.tot, knots = nk2, bs = "te...
2005 Feb 24
2
a question about function eval()
Hi, I have a question about the usage of eval(). Wonder if any experienced user can help me out of it. I use eval() in the following function: semireg.pwl <- function(coef.s=rnorm(1),coef.a=rnorm(1),knots.pos=knots.x,knots.ini.val=knots.val){ knotn <- length(knots.pos) def.par.env <- sys.frame(1) print(def.par.env) print(environment(coef.s)) tg <- eval( (parse(text= paste( "function(coef.sex=coef.s,coef.age=coef.a,",...
2005 Apr 15
2
negetative AIC values: How to compare models with negative AIC's
Dear, When fitting the following model knots <- 5 lrm.NDWI <- lrm(m.arson ~ rcs(NDWI,knots) I obtain the following result: Logistic Regression Model lrm(formula = m.arson ~ rcs(NDWI, knots)) Frequencies of Responses 0 1 666 35 Obs Max Deriv Model L.R. d.f. P C Dxy Gamma Tau-a...
2007 Jul 04
3
Problem/bug with smooth.spline and all.knots=T
Dear list, if I do smooth.spline(tmpSec, tmpT, all.knots=T) with the attached data, I get this error-message: Error in smooth.spline(tmpSec, tmpT, all.knots = T) : smoothing parameter value too small If I do smooth.spline(tmpSec[-single arbitrary number], tmpT[-single arbitrary number], all.knots=T) it works! I just don't see it. It work...
2008 Mar 24
1
Great difference for piecewise linear function between R and SAS
Dear Rusers, I am now using R and SAS to fit the piecewise linear functions, and what surprised me is that they have a great differrent result. See below. #R code--Knots for distance are 16.13 and 24, respectively, and Knots for y are -0.4357 and -0.3202 m.glm<-glm(mark~x+poly(elevation,2)+bs(distance,degree=1,knots=c(16.13,24)) +bs(y,degree=1,knots=c(-0.4357,-0.3202 )),family=binomial(logit),data=point) summary(m.glm) Coefficients:...
2013 May 28
3
R-3.0.1 - "transient" make check failure in splines-EX.r
...2bit using OpenBlas (successor to GotoBlas) (Nehalem - corei7), and the compiled version passes all tests except for the "splines-Ex" test in the exact same place that Paul had issues: ~~~~ > stopifnot(identical(ns(x), ns(x, df = 1)), + identical(ns(x, df = 2), ns(x, df = 2, knots = NULL)), # not true till 2.15.2 + !is.null(kk <- attr(ns(x), "knots")), # not true till 1.5.1 + length(kk) == 0) Error: identical(ns(x, df = 2), ns(x, df = 2, knots = NULL)) is not TRUE ~~~~ Yet, opening up R and running the actual code shows that the error is tra...
2009 Sep 30
1
rcs fits in design package
...1904 1672 1 I want to use post_op_prw as a predictor variable in an OLS model. I decided to fit it using a restricted cubic spline. But, I'm seeing behavior I don't understand. See below: > rcspline.eval(amb$post_op_prw,nk = 3, knots.only = T) [1] 0.0000000 0.6147927 0.9092937 0.9667178 Warning message: In rcspline.eval(amb$post_op_prw, nk = 3, knots.only = T) : could not obtain 3 knots with default algorithm. Used alternate algorithm to obtain 4 knots > rcspline.eval(amb$post_op_prw,nk = 4, knots.only = T) [1] 0.0...
2013 Feb 27
1
Finding the knots in a smoothing spline using nknots
Hi r-helpers. Please forgive my ignorance, but I would like to plot a smoothing spline (smooth.spline) from package "stats", and show the knots in the plot, and I can't seem to figure out where smooth.spline has located the knots (when I use nknots). Unfortunately, I don't know a lot about splines, but I know that they provide me an easy way to estimate the location of local maxima and minima on varying time-scales (number of knot...
2009 Oct 13
2
How to choose a proper smoothing spline in GAM of mgcv package?
Hi, there, I have 5 datasets. I would like to choose a basis spline with same knots in GAM function in order to obtain same basis function for 5 datasets. Moreover, the basis spline is used to for an interaction of two covarites. I used "cr" in one covariate, but it can only smooth w.r.t 1 covariate. Can anyone give me some suggestion about how to choose a proper smooth...
2013 Jan 10
2
piece-wise linear regression nls function
windows 7, R 2.12 I am trying to run a piecewise linear regression with a single knot, i.e. a regression composed of two straight lines where the two lines intersect at an x value given by the variable knot. I wish to estimate the slope of both lines, the value of knot, the x value where the two lines intersect, and an intercept. I am using the nls code below, and get the following error
2008 May 01
1
Optimal knot locations for splines
Suppose I have two variables, x and y. For a fixed number of knots, I want to create a spline transformation of x such that a loss function is minimized. Presumably, this loss function would be least squares, i.e. sum (f(x)-y)^2. The spline transformations would be linear, quadratic or cubic. I know I can solve this problem using some optimization function in R...
2009 Sep 20
1
How to choose knots for GAM?
Hi, all I want to choose same knots in GAM for 10 different studies so that they has the same basis function. Even though I choose same knots and same dimensions of basis smoothing, the basis representations are still not same. My command is as follows: data.gam<-gam(y~s(age,bs='cr',k=10)+male,family=binomial,knots=list(...
2010 Dec 23
2
Piece-wise continuous regression with one knot
Windows Vista R 2.10 - I know it is old, I will update later today. How might I perform a piece-wise linear regression where two linear segments are separated by a single knot? In addition to estimating the slopes of the two segments (or the slope in one segment and the difference between the slope of the first and second segment), I would like the analysis to select the optimum knot. My first
2006 Nov 15
1
splineDesign and not-a-knot conditions
Hi, I would like to fit an (interpolating) spline to data where the derivatives at the endpoints of the interval are nonzero, thus the natural spline endpoint-specification does not make sense. Books (de Boor, etc) suggest that in this case I use not-a-knot splines. I know what not-a-knot splines are (so if I were solving for the coefficients directly I knew how to do this), but I don't