splines

What is the R equivalent of matlab's csaps()

佐手、 提交于 2019-12-05 12:57:47
csaps() in matlab does a cubic spline according to a particular definition of the smoothing parameter p . Here is some matlab code and its result: % x variable age = 75:99 % y variable diffs = [-39 -2 -167 -21 -13 32 -37 -132 -143 -91 -93 -88 -62 -112 -95 -28 -90 -40 -27 -23 -28 -11 -8 -6 1] % 0.0005 is the parameter p, and the later specification of % age are the desired x for prediction csaps(age,diffs,0.0005,age) % result (column headers removed): -63.4604 -64.0474 -64.6171 -65.1397 -65.6111 -66.0165 -66.3114 -66.4123 -66.2229 -65.6726 -64.7244 -63.3582 -61.5676 -59.3568 -56.7364 -53.7382

Emulating Excel's “scatter with smooth curve” spline function in Matplotlib for 3 points

半世苍凉 提交于 2019-12-05 02:18:10
问题 I'm trying to emulate Excel's Insert>Scatter>Scatter with smooth lines and markers command in Matplotlib The scipy function interpolate creates a similar effect, with some nice examples of how to simply implement this here: How to draw cubic spline in matplotlib However Excel's spline algorithm is also able to generate a smooth curve through just three points (e.g. x = [0,1,2] y = [4,2,1]); and it isn't possible to do this with cubic splines. I have seen discussions that suggest that the

How to get confidence interval for smooth.spline?

血红的双手。 提交于 2019-12-04 14:51:49
I have used smooth.spline to estimate a cubic spline for my data. But when I calculate the 90% point-wise confidence interval using equation, the results seems to be a little bit off. Can someone please tell me if I did it wrongly? I am just wondering if there is a function that can automatically calculate a point-wise interval band associated with smooth.spline function. boneMaleSmooth = smooth.spline( bone[males,"age"], bone[males,"spnbmd"], cv=FALSE) error90_male = qnorm(.95)*sd(boneMaleSmooth$x)/sqrt(length(boneMaleSmooth$x)) plot(boneMaleSmooth, ylim=c(-0.5,0.5), col="blue", lwd=3, type=

B-spline curves

心已入冬 提交于 2019-12-04 13:35:21
I have a set of points which I want to smooth using B-spline curves. My question is how can I implement B-spline curves to smooth these set of points? I want to implement this using c++. Here is a function for any given number of points: void Spline(double x[N+1],double y[N+1], // input double A[N],double B[N], // output double C[N],double D[N]) // output { double w[N]; double h[N]; double ftt[N+1]; for (int i=0; i<N; i++) { w[i] = (x[i+1]-x[i]); h[i] = (y[i+1]-y[i])/w[i]; } ftt[0] = 0; for (int i=0; i<N-1; i++) ftt[i+1] = 3*(h[i+1]-h[i])/(w[i+1]+w[i]); ftt[N] = 0; for (int i=0; i<N; i++) { A

Emulating Excel's “scatter with smooth curve” spline function in Matplotlib for 3 points

我是研究僧i 提交于 2019-12-03 21:34:23
I'm trying to emulate Excel's Insert>Scatter>Scatter with smooth lines and markers command in Matplotlib The scipy function interpolate creates a similar effect, with some nice examples of how to simply implement this here: How to draw cubic spline in matplotlib However Excel's spline algorithm is also able to generate a smooth curve through just three points (e.g. x = [0,1,2] y = [4,2,1]); and it isn't possible to do this with cubic splines. I have seen discussions that suggest that the Excel algorithm uses Catmull-Rom splines; but don't really understand these, or how they could be adapted

Point Sequence Interpolation

佐手、 提交于 2019-12-03 19:56:00
问题 Given an arbitrary sequence of points in space, how would you produce a smooth continuous interpolation between them? 2D and 3D solutions are welcome. Solutions that produce a list of points at arbitrary granularity and solutions that produce control points for bezier curves are also appreciated. Also, it would be cool to see an iterative solution that could approximate early sections of the curve as it received the points, so you could draw with it. 回答1: The Catmull-Rom spline is guaranteed

Is there a Python equivalent to the smooth.spline function in R

孤者浪人 提交于 2019-12-03 16:46:18
问题 The smooth.spline function in R allows a tradeoff between roughness (as defined by the integrated square of the second derivative) and fitting the points (as defined by summing the squares of the residuals). This tradeoff is accomplished by the spar or df parameter. At one extreme you get the least squares line, and the other you get a very wiggly curve which intersects all of the data points (or the mean if you have duplicated x values with different y values) I have looked at scipy

Is there a Python equivalent to the smooth.spline function in R

橙三吉。 提交于 2019-12-03 05:04:49
The smooth.spline function in R allows a tradeoff between roughness (as defined by the integrated square of the second derivative) and fitting the points (as defined by summing the squares of the residuals). This tradeoff is accomplished by the spar or df parameter. At one extreme you get the least squares line, and the other you get a very wiggly curve which intersects all of the data points (or the mean if you have duplicated x values with different y values) I have looked at scipy.interpolate.UnivariateSpline and other spline variants in Python, however, they seem to only tradeoff by

How to plot a Cox hazard model with splines

好久不见. 提交于 2019-12-03 03:45:31
I have a following model: coxph(Surv(fulength, mortality == 1) ~ pspline(predictor)) where is fulength is a duration of follow-up (including mortality), predictor is a predictor of mortality. The output of the command above is this: coef se(coef) se2 Chisq DF p pspline(predictor), line 0.174 0.0563 0.0562 9.52 1.00 0.002 pspline(predictor), nonl 4.74 3.09 0.200 How can I plot this model so that I get the nice curvy line with 95% confidence bands and hazard ratio on the y axis? What I am aiming for is something similar to this: This is when you get when you run the first example in ?cph of the

mgcv: Extract Knot Locations for `tp` smooth from a GAM model

南笙酒味 提交于 2019-12-02 02:51:31
I am trying to extract the placement of the knots from a GAM model in order to delineate my predictor variable into categories for another model. My data contains a binary response variable (used) and a continuous predictor (open). data <- data.frame(Used = rep(c(1,0,0,0),1250), Open = round(runif(5000,0,50), 0)) I fit the GAM as such: mod <- gam(Used ~ s(Open), binomial, data = data) I can get the predicted values, and the model matrix etc with either type=c("response", "lpmatrix") within the predict.gam function but I am struggling with out to extract the knot locations at which which the