splines

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

本秂侑毒 提交于 2019-12-31 03:06:28
问题 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

how to use Eigen for B-Splines for noisy sequence data

馋奶兔 提交于 2019-12-23 20:26:04
问题 In the below picture, the spap2 function is used in Matlab to smooth noisy data. The result is very good. Eigen library supports this functionality Splines. I'm looking for an example in Eigen to obtain similar results. For the Matlab, I've used spap2(4, 4, time, noisyY); Data is provided in this format time noisyData 1.766 6.61202 1.767 11.4159 1.768 8.29416 1.769 8.29416 1.77 8.29416 1.771 6.02606 1.772 4.37819 1.773 4.37819 1.774 4.37819 1.775 3.18094 1.776 2.31109 1.777 1.67911 1.778 1

Behavior of scipy's splrep

陌路散爱 提交于 2019-12-23 16:15:46
问题 I have a set of data points and would like to approximate them with a spline function. I used two different functions: splrep from scipy and a cubic spline function that I found here. The results look like this. The code is as follows: from matplotlib.pyplot import * from numpy import * from scipy import interpolate #---------------------------------------------- s = arange(257)/256.0 z = s[::-1] b = transpose(array((z*z*z, 3*z*z*s, 3*z*s*s, s*s*s))) def cubicspline(c,t): return dot(b[t],c) #

Drawing aliased, pixel-perfect 1px splines (Catmull-Rom, specifically)

徘徊边缘 提交于 2019-12-21 04:36:06
问题 A brief background: I'm working on a web-based drawing application and need to draw 1px thick splines that pass through their control points. The issue I'm struggling with is that I need to draw each of the pixels between p1 and p2 as if I were using a 1px pencil tool. So, no anti-aliasing and one pixel at a time. This needs to be done manually without the use of any line/curve library code as my brush system depends upon having a pixel coordinate to apply the brush tip to the canvas.

How to plot a Cox hazard model with splines

只愿长相守 提交于 2019-12-20 16:21: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

How to plot a Cox hazard model with splines

核能气质少年 提交于 2019-12-20 16:21:20
问题 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

non-conformable arguments error from lmer when trying to extract information from the model matrix

梦想与她 提交于 2019-12-11 12:03:43
问题 I have some longitudinal data from which I'd like to get the predicted means at specified times. The model includes 2 terms, their interaction and a spline term for the time variable. When I try to obtain the predicted means, I get "Error in mm %*% fixef(m4) : non-conformable arguments" I've used the sleep data set from lmer to illustrate my problem. First, I import the data and create a variable "age" for my interaction sleep <- as.data.frame(sleepstudy) #get the sleep data # create fake

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

断了今生、忘了曾经 提交于 2019-12-07 11:41:41
问题 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

How to get confidence interval for smooth.spline?

孤者浪人 提交于 2019-12-06 08:44:35
问题 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

B-spline curves

橙三吉。 提交于 2019-12-06 08:38:34
问题 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++. 回答1: 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;