1
$\begingroup$

I am using "segment" package in R for fitting piecewise linear segments to a sample parabolic curve in R. I am not able to able to interpret the functions "psi" and "segZ" from the R documentation. I have two variables X and Y . If we consider X as dependent and Y as independent variable then,

reg<- lm(Y~X, data = curved_data)

I am creating a parabola from the sample data given below-

x<- c(-37, -36, -35, -34, -33, -32, -30, -28, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -12, -10, -8, -7, -5, -4, -2, -1, 0, 1, 2, 4, 5, 7, 8, 10, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 30, 32, 33, 34, 35, 36, 37)

y=4x^2

That is I am constructing a parabola with the help of the above equation in R.

So in this case y is independent and x is the dependent variable.

I want to have a piece wise linearity fit for this parabolala.

I have tried using two different codes of R i.e.

seg_model<- segmented(reg, seg.Z = ~curved_data$X, psi = c(-35, 4, 30), control = seg.control(display = TRUE))

-35, 4, 30 are the 3 breakpoints that are chosen by me. Are they correctly chosen? How should they be chosen?

I get the error

Error in segmented(reg, seg.Z = ~curved_data$X, psi = c(-35, 4, 30), : psi' should be a list with more than one covariate inseg.Z'

What does this error means?

Also I have tried using code by writing psi = NA

I have got the below error

Error in segmented(reg, seg.Z = ~curved_data$X, psi = NA, control = seg.control(display = TRUE)) : psi' should be a list with more than one covariate inseg.Z'

I am not able to understand psi and segZ from the R documentation. Please can I get an elaborate functioning of these two functions? What is the relation between psi and segZ? What should I do to correct this error? Does number of points in vector of psi means number of breakpoints OR what is it?

$\endgroup$

1 Answer 1

1
$\begingroup$

You must attach the data frame curved_data before running the commands. Then, run your command like this:

seg_model <- segmented(reg, seg.Z = ~X, psi = c(-35, 4, 30),
                       control = seg.control(display = TRUE))
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.