spline

How to replace NA values in a data.table with na.spline

末鹿安然 提交于 2021-02-16 20:09:06
问题 I'm trying to prepare some demographic data retrieved from Eurostat for further processing, amongst others replacing any missing data with corresponding approximated ones. First I was using data.frames only, but then I got convinced that data.tables might offer some advantages over regular data.frames, so I migrated to data.tables. One thing I've observed while doing so was getting different results when using "na.spline" in combination with "apply" versus "na.spline" as part of the data

Get subject-specific peak velocity and age at peak velocity values from linear mixed spline models

喜你入骨 提交于 2021-02-08 04:01:55
问题 I am fitting a linear mixed effects model with a natural spline function for age in order to describe the nonlinear trajectory for a repeated outcome y (bone mineral content in grams) across time ( age in years). How can I solve the spline derivatives to get the velocity curve and estimate for each individual their peak velocity (grams/year) and age at peak velocity (years) from this model? This is the example data dat <- structure(list(id = c(1001L, 1001L, 1001L, 1001L, 1001L, 1002L, 1003L,

Get subject-specific peak velocity and age at peak velocity values from linear mixed spline models

爷,独闯天下 提交于 2021-02-08 04:01:27
问题 I am fitting a linear mixed effects model with a natural spline function for age in order to describe the nonlinear trajectory for a repeated outcome y (bone mineral content in grams) across time ( age in years). How can I solve the spline derivatives to get the velocity curve and estimate for each individual their peak velocity (grams/year) and age at peak velocity (years) from this model? This is the example data dat <- structure(list(id = c(1001L, 1001L, 1001L, 1001L, 1001L, 1002L, 1003L,

R - Extract ns spline object from lmer model and predict on new data

纵然是瞬间 提交于 2021-02-07 10:31:19
问题 I'm looking to predict 'terms', especially ns splines, from an lmer model. I've replicated the problem with the mtcars dataset (technically poor example, but works to get the point across). Here is what I'm trying to do with a linear model: data(mtcars) mtcarsmodel <- lm(wt ~ ns(drat,2) + hp + as.factor(gear), data= mtcars) summary(mtcarsmodel) coef(mtcarsmodel) test <- predict(mtcarsmodel, type = "terms") Perfect. However, there is no equivalent 'terms' option for lmer predict (unresolved

R - Extract ns spline object from lmer model and predict on new data

馋奶兔 提交于 2021-02-07 10:31:04
问题 I'm looking to predict 'terms', especially ns splines, from an lmer model. I've replicated the problem with the mtcars dataset (technically poor example, but works to get the point across). Here is what I'm trying to do with a linear model: data(mtcars) mtcarsmodel <- lm(wt ~ ns(drat,2) + hp + as.factor(gear), data= mtcars) summary(mtcarsmodel) coef(mtcarsmodel) test <- predict(mtcarsmodel, type = "terms") Perfect. However, there is no equivalent 'terms' option for lmer predict (unresolved

Convert a B-Spline into Bezier curves

て烟熏妆下的殇ゞ 提交于 2021-02-07 08:27:22
问题 I have a B-Spline curve. I have all the knots, and the x,y coordinates of the Control Points. I need to convert the B-Spline curve into Bezier curves. My end goal is to be able to draw the shape on an html5 canvas element. The B-Spline is coming from a dxf file which doesn't support Beziers, while a canvas only supports Beziers. I've found several articles which attempt to explain the process, however they are quite a bit over my head and really seem to be very theory intensive. I really need

Convert a B-Spline into Bezier curves

做~自己de王妃 提交于 2021-02-07 08:26:02
问题 I have a B-Spline curve. I have all the knots, and the x,y coordinates of the Control Points. I need to convert the B-Spline curve into Bezier curves. My end goal is to be able to draw the shape on an html5 canvas element. The B-Spline is coming from a dxf file which doesn't support Beziers, while a canvas only supports Beziers. I've found several articles which attempt to explain the process, however they are quite a bit over my head and really seem to be very theory intensive. I really need

Individual age at peak velocity from linear mixed natural spline model

耗尽温柔 提交于 2021-01-29 12:49:00
问题 This thread continues with Get subject-specific peak velocity and age at peak velocity values from linear mixed spline models. I am fitting a linear mixed effects model with a natural spline function for age. I would like to estimate age at peak velocity (apv - years) and peak velocity (pv - grams) for each person in the dataset by differentiating the spline terms. The model includes a random quadratic slope for age. How can I estimate the person-specific apv and pv? I am using the

Create BSpline from knots and coefficients

半世苍凉 提交于 2021-01-27 19:20:23
问题 How can a spline be created if only the points and the coefficients are known? I'm using scipy.interpolate.BSpline here, but am open to other standard packages as well. So basically I want to be able to give someone just those short arrays of coefficients for them to be able to recreate the fit to the data. See the failed red-dashed curve below. import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import BSpline, LSQUnivariateSpline x = np.linspace(0, 10, 50) # x-data y =

Create BSpline from knots and coefficients

不想你离开。 提交于 2021-01-27 18:14:39
问题 How can a spline be created if only the points and the coefficients are known? I'm using scipy.interpolate.BSpline here, but am open to other standard packages as well. So basically I want to be able to give someone just those short arrays of coefficients for them to be able to recreate the fit to the data. See the failed red-dashed curve below. import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import BSpline, LSQUnivariateSpline x = np.linspace(0, 10, 50) # x-data y =