Questions tagged [piecewise]

"piecewise" may refer to a piecewise function, a piecewise interpolation or a piecewise regression / smoothing.

Defining a piecewise function normally requires writing if ... else ... clause.

Interpolation is inherently piecewise.

Piecewise regression often refers to piecewise linear regression, or segmented regression.

367 questions
0
votes
2 answers

Piecewise linear regression with constraint - r

I am trying to do a piecewise linear OLS regression analysis in R, with one breakpoint. I have the following regression formula and restrictions: Where D is a dummy. I would like to impose a restriction, so that the regression lines are continous…
perf2k
  • 43
  • 5
0
votes
0 answers

Interpretation of error in sem.coef

I am trying to run a sem with a random effect in piecewiseSEM. My model runs with no error, and sem.fit() also runs with no error or warnings. However, when I run sem.coefs() I get the following warning: 1: In if (grepl("cbind",…
Danielle
  • 23
  • 3
0
votes
1 answer

Cryptic error when using HIPS autograd with numpy.piecewise (ValueError: setting an array element with a sequence.)

I want to use HIPS autograd (https://github.com/HIPS/autograd) in Python 2.7 (in Jupyter notebook) to find a parameter x. My forward model (observations at given time points t as a function of the parameter x) is a piecewise function of t.…
0
votes
2 answers

Piece wise function without predefined intervals

I want to make an .m file that represents a piece wise function and returns a vector with all the discrete values calculated. To be a bit more clear, I want a function (which I have named Iapp and is time dependant, so Iapp(t)) that returns zero for…
Desperados
  • 434
  • 5
  • 13
0
votes
1 answer

Collect puzzle from curve fragments

I have a data, which consists of a number of chunks. I now that they come from some continuous curve, but later were shifted in the y-direction. Now I want to shift them back to estimate original curve. Some parts are not shifted, but just absent.…
zlon
  • 812
  • 8
  • 24
0
votes
0 answers

Extracting slopes and intercepts from splines2 results

I was trying to teach myself the math behind what produces the slope and intercept of a segmented variable in the segmented package using the plant data set. My plan was to run a model through the segmented package, produce the slopes and intercept…
Jordan
  • 1,415
  • 3
  • 18
  • 44
0
votes
3 answers

piecewise regression in r

I have two variables, A and B, that are significantly related if modeled in a piecewise regression. The model has two segments. The problem is that in the plot, the two segments do not connect to one another the way they should: they form a 'nose'…
Chris Ruehlemann
  • 20,321
  • 4
  • 12
  • 34
0
votes
1 answer

Matlab piecewise function in same plot as continuous

I'm trying to plot a piecewise function as an interpolation for the function f(x) = 1/(1+25x^2). This is how I plotted two functions previously when I wasn't dealing with piecewise. z = linspace(-1,1,200); yexact =…
Matt Robbins
  • 429
  • 2
  • 5
  • 10
0
votes
1 answer

using R segmented package with lognormal errors

My model is: y = f(x) exp(E) where E~N(0,sig^2) where f(x) = piece-wise linear model (ax + bI(x-d)(x-d)) (a and b are parameters, d = breakpoint, I = indicator function) s.t log (y) = log(f(x)) + E I have coded: lin.mod <- lm(y~x -…
andy
  • 185
  • 9
0
votes
1 answer

Can I do a mulitvariate regression with the segmented package in r?

I have FINALLY figured out how to use the segmented package with a uni-variate analysis giving results comparable to what I was expecting. Ultimately though, I have to do a GLM piece-wise regression on a multivariate analysis. The model has some…
Jordan
  • 1,415
  • 3
  • 18
  • 44
0
votes
2 answers

Python, numpy, piecewise answer gets rounded

I have a question with regards to the outputs of numpy.piecewise. my code: e=110 f=np.piecewise(e,[e<120,e>=120],[1/4,1]) print(f) As a result i get: 0 and not the desired 0.25 Can someone explain me why piecewise seems to be rounding my answer? Is…
Jonasz
  • 363
  • 3
  • 4
0
votes
1 answer

Repeat Maple Piecewise Plot

I have: h(t):=piecewise(0<=t<2,2-t,2<=t<=3,2t-4) Then I use: plot(h(t),t=0..6,y=-1..3,scaling=constrained) My intention was to create a period of 2 by making a larger interval. This didn't solved my problem. How would I be able to create two…
0
votes
1 answer

Piecewise regression python

I am trying to do a piecewise linear regression in Python and the data looks like this, I need to fit 3 lines for each section. Any idea how? I am having the following code, but the result is shown below. Any help would be appreciated. import…
Ranjani.S
  • 3
  • 3
0
votes
1 answer

How do I extract the function from a piecewise defined function in Matlab?

I'm using the new Matlab piecewise function (https://www.mathworks.com/help/symbolic/piecewise.html ) introduced in the Symbolic Math Toolbox R2016b to define a function, and I'm trying to extract the function. Specifically my code looks something…
0
votes
1 answer

Problems plotting multiple functions and data points together using ggplot2 in r

I am trying to plot 5 functions and 5 data points on the same plot using the ggplot2 package. The code works when I am just plotting the functions, but as soon as I add the data points, the it takes very long time to process. If I only add one…
Gro
  • 1
  • 2