Skip to main content
added 386 characters in body
Source Link
Ian S
  • 69
  • 1
  • 3

This is different, follow up question to someone else's question here:

I am very new to R and have no programming experience what so ever but I am holding my own for the data analysis we need in my lab. I am detecting changepoints in physiological data using cpt.mean() and until now I have been doing two separate linear regressions with lm(). One for the first half of my data on each sideand another for my second half of my data. I determine where to divide up the data after cpt.mean() tells me my changepoint. To make sureThe first line would normally have a slope around 0 and the lines connectedother could be anywhere from 0.2 to 2. I was finding the intercept ofwould then add those lines separately to my two best fit liesgraph and clippingclip them up to and from their intersection so that it was a smooth break point in what looked like a continuous "checkmark"appeared that I only had only line graphed but that that line had a "corner." At first it worked really well with one study and the intersections were very close to the changepoints cpt.mean() found. Now we are on a study that has data that isn't as clean andbut the intersection ofpoint where the two lines is very farjoined together was often further from the changepoint found with cpt.mean because what I graphed was determined by where the two equations mathematically intersected. 

So I thought it would be better to find linear regression lines that anchor to the changepoint. That way when I graph two seperate lines, they connect at the changepoint that cpt.mean. I have read and understand the basic solution to this question linked above but I cant seem to figure out how to limit which data it looks at for the linear regression so that it only fits half of the data. Normally I do something like this if

In a made up scenario my changepoint was thecould be my 26th data point and(10, 20)

Normally I needed to perform a linear regressiondo something like this for only the first 26half of the data points: (PP is my X and MAP is my Y variable):

lm(MAP[1:26]~PP[1:26])

The simple solution to anchoring the best fit line to a specific point,(X0, Y0) was this

lm(I(y-y0)~I(x-x0) + 0)

with my variables and changepoint:

lm(I(MAP-y020)~I(PP-x010) + 0)

I figured I could just combine the two as follows:

lm(I(MAP[1:26]-y020)~I(PP[1:26]-x010) +0)

No error came up but nothing showed up on my scatter plot. Not sure whats happening.


 

My data has a "baseline" and then thereHere is a clear increase in the slope of the data. I performed a change point analysis to find where the data started increasing rapidly. Normally I take all of the data to the left of the changepoint and do linear regression. Then I take all the data to the rightan example of the changepoint and do another regression. I then take the two equations and plot them separately but I clip the lines so that it appears to have one line that has a "corner" or "elbow". Both options Glen_b listed seem appealing. I am mostly concerned with the x value.what my graphs normally look like: enter image description here

Best, Ian

This is different, follow up question to someone else's question here:

I am very new to R and have no programming experience what so ever but I am holding my own for the data analysis we need in my lab. I am detecting changepoints in physiological data using cpt.mean() and until now I have been doing two separate linear regressions with lm() for the data on each side of the changepoint. To make sure the lines connected I was finding the intercept of my two best fit lies and clipping them up to and from their intersection so it was a smooth break point in what looked like a continuous "checkmark" line. At first it worked really well with one study and the intersections were very close to the changepoints cpt.mean() found. Now we are on a study that has data that isn't as clean and the intersection of the two lines is very far from the changepoint. So I thought it would be better to find linear regression lines that anchor to the changepoint. I have read and understand the basic solution to this question linked above but I cant seem to figure out how to limit which data it looks at for the linear regression. Normally I do something like this if my changepoint was the 26th data point and I needed to perform a linear regression for only the first 26 data points (PP is my X and MAP is my Y variable):

lm(MAP[1:26]~PP[1:26])

The simple solution to anchoring the best fit line to a specific point,(X0, Y0) was this

lm(I(y-y0)~I(x-x0) + 0)

with my variables:

lm(I(MAP-y0)~I(PP-x0) + 0)

I figured I could just combine the two as follows:

lm(I(MAP[1:26]-y0)~I(PP[1:26]-x0) +0)

No error came up but nothing showed up on my scatter plot. Not sure whats happening.


 

My data has a "baseline" and then there is a clear increase in the slope of the data. I performed a change point analysis to find where the data started increasing rapidly. Normally I take all of the data to the left of the changepoint and do linear regression. Then I take all the data to the right of the changepoint and do another regression. I then take the two equations and plot them separately but I clip the lines so that it appears to have one line that has a "corner" or "elbow". Both options Glen_b listed seem appealing. I am mostly concerned with the x value.

This is different, follow up question to someone else's question here:

I am very new to R and have no programming experience what so ever but I am holding my own for the data analysis we need in my lab. I am detecting changepoints in physiological data using cpt.mean() and until now I have been doing two separate linear regressions with lm(). One for the first half of my data and another for my second half of my data. I determine where to divide up the data after cpt.mean() tells me my changepoint. The first line would normally have a slope around 0 and the other could be anywhere from 0.2 to 2. I would then add those lines separately to my graph and clip them so that it appeared that I only had only line graphed but that that line had a "corner." At first it worked really well but the point where the two lines joined together was often further from the changepoint found with cpt.mean because what I graphed was determined by where the two equations mathematically intersected. 

So I thought it would be better to find linear regression lines that anchor to the changepoint. That way when I graph two seperate lines, they connect at the changepoint that cpt.mean. I have read and understand the basic solution to this question linked above but I cant seem to figure out how to limit the regression so that it only fits half of the data.

In a made up scenario my changepoint could be my 26th data point (10, 20)

Normally I do something like this for the first half of the data: (PP is my X and MAP is my Y variable):

lm(MAP[1:26]~PP[1:26])

The simple solution to anchoring the best fit line to a specific point,(X0, Y0) was this

lm(I(y-y0)~I(x-x0) + 0)

with my variables and changepoint:

lm(I(MAP-20)~I(PP-10) + 0)

I figured I could just combine the two as follows:

lm(I(MAP[1:26]-20)~I(PP[1:26]-10) +0)

No error came up but nothing showed up on my scatter plot. Not sure whats happening.

Here is an example of a what my graphs normally look like: enter image description here

Best, Ian

Post Reopened by whuber
added 569 characters in body
Source Link
whuber
  • 333.5k
  • 63
  • 792
  • 1.3k

This is different, follow up question to someone else's question here:

I am very new to R and have no programming experience what so ever but I am holding my own for the data analysis we need in my lab. I am detecting changepoints in physiological data using cpt.mean() and until now I have been doing two separate linear regressions with lm() for the data on each side of the changepoint. To make sure the lines connected I was finding the intercept of my two best fit lies and clipping them up to and from their intersection so it was a smooth break point in what looked like a continuous "checkmark" line. At first it worked really well with one study and the intersections were very close to the changepoints cpt.mean() found. Now we are on a study that has data that isn't as clean and the intersection of the two lines is very far from the changepoint. So I thought it would be better to find linear regression lines that anchor to the changepoint. I have read and understand the basic solution to this question linked above but I cant seem to figure out how to limit which data it looks at for the linear regression. Normally I do something like this if my changepoint was the 26th data point and I needed to perform a linear regression for only the first 26 data points (PP is my X and MAP is my Y variable):

lm(MAP[1:26]~PP[1:26])

The simple solution to anchoring the best fit line to a specific point,(X0, Y0) was this

lm(I(y-y0)~I(x-x0) + 0)

with my variables:

lm(I(MAP-y0)~I(PP-x0) + 0)

I figured I could just combine the two as follows:

lm(I(MAP[1:26]-y0)~I(PP[1:26]-x0) +0)

No error came up but nothing showed up on my scatter plot. Not sure whats happening.

 

Best, IanMy data has a "baseline" and then there is a clear increase in the slope of the data. I performed a change point analysis to find where the data started increasing rapidly. Normally I take all of the data to the left of the changepoint and do linear regression. Then I take all the data to the right of the changepoint and do another regression. I then take the two equations and plot them separately but I clip the lines so that it appears to have one line that has a "corner" or "elbow". Both options Glen_b listed seem appealing. I am mostly concerned with the x value.

This is different, follow up question to someone else's question here:

I am very new to R and have no programming experience what so ever but I am holding my own for the data analysis we need in my lab. I am detecting changepoints in physiological data using cpt.mean() and until now I have been doing two separate linear regressions with lm() for the data on each side of the changepoint. To make sure the lines connected I was finding the intercept of my two best fit lies and clipping them up to and from their intersection so it was a smooth break point in what looked like a continuous "checkmark" line. At first it worked really well with one study and the intersections were very close to the changepoints cpt.mean() found. Now we are on a study that has data that isn't as clean and the intersection of the two lines is very far from the changepoint. So I thought it would be better to find linear regression lines that anchor to the changepoint. I have read and understand the basic solution to this question linked above but I cant seem to figure out how to limit which data it looks at for the linear regression. Normally I do something like this if my changepoint was the 26th data point and I needed to perform a linear regression for only the first 26 data points (PP is my X and MAP is my Y variable):

lm(MAP[1:26]~PP[1:26])

The simple solution to anchoring the best fit line to a specific point,(X0, Y0) was this

lm(I(y-y0)~I(x-x0) + 0)

with my variables:

lm(I(MAP-y0)~I(PP-x0) + 0)

I figured I could just combine the two as follows:

lm(I(MAP[1:26]-y0)~I(PP[1:26]-x0) +0)

No error came up but nothing showed up on my scatter plot. Not sure whats happening.

Best, Ian

This is different, follow up question to someone else's question here:

I am very new to R and have no programming experience what so ever but I am holding my own for the data analysis we need in my lab. I am detecting changepoints in physiological data using cpt.mean() and until now I have been doing two separate linear regressions with lm() for the data on each side of the changepoint. To make sure the lines connected I was finding the intercept of my two best fit lies and clipping them up to and from their intersection so it was a smooth break point in what looked like a continuous "checkmark" line. At first it worked really well with one study and the intersections were very close to the changepoints cpt.mean() found. Now we are on a study that has data that isn't as clean and the intersection of the two lines is very far from the changepoint. So I thought it would be better to find linear regression lines that anchor to the changepoint. I have read and understand the basic solution to this question linked above but I cant seem to figure out how to limit which data it looks at for the linear regression. Normally I do something like this if my changepoint was the 26th data point and I needed to perform a linear regression for only the first 26 data points (PP is my X and MAP is my Y variable):

lm(MAP[1:26]~PP[1:26])

The simple solution to anchoring the best fit line to a specific point,(X0, Y0) was this

lm(I(y-y0)~I(x-x0) + 0)

with my variables:

lm(I(MAP-y0)~I(PP-x0) + 0)

I figured I could just combine the two as follows:

lm(I(MAP[1:26]-y0)~I(PP[1:26]-x0) +0)

No error came up but nothing showed up on my scatter plot. Not sure whats happening.

 

My data has a "baseline" and then there is a clear increase in the slope of the data. I performed a change point analysis to find where the data started increasing rapidly. Normally I take all of the data to the left of the changepoint and do linear regression. Then I take all the data to the right of the changepoint and do another regression. I then take the two equations and plot them separately but I clip the lines so that it appears to have one line that has a "corner" or "elbow". Both options Glen_b listed seem appealing. I am mostly concerned with the x value.

Post Closed as "Needs details or clarity" by Firebug, Michael R. Chernick, mdewey, Peter Flom
added 69 characters in body
Source Link
Ian S
  • 69
  • 1
  • 3

This is different, follow up question to someone else's question here:

I am very new to R and have no programming experience what so ever but I am holding my own for the data analysis we need in my lab. I am detecting changepoints in physiological data using cpt.mean() and until now I have been doing two separate linear regressions with lm() for the data on each side of the changepoint. To make sure the lines connected I was finding the intercept of my two best fit lies and clipping them up to and from their intersection so it was a smooth break point in what looked like a continuous "checkmark" line. At first it worked really well with one study and the intersections were very close to the changepoints cpt.mean() found. Now we are on a study that has data that isn't as clean and the intersection of the two lines is very far from the changepoint. So I thought it would be better to find linear regression lines that anchor to the changepoint. I have read and understand the basic solution to this question here:linked above but I cant seem to figure out how to limit which data it looks at for the linear regression. Normally I do something like this if my changepoint was the 26th data point and I needed to perform a linear regression for only the first 26 data points (PP is my X and MAP is my Y variable):

lm(MAP[1:26]~PP[1:26])

The simple solution to anchoring the best fit line to a specific point,(X0, Y0) was this

lm(I(y-y0)~I(x-x0) + 0)

with my variables:

lm(I(MAP-y0)~I(PP-x0) + 0)

I figured I could just combine the two as follows:

lm(I(MAP[1:26]-y0)~I(PP[1:26]-x0) +0)

No error came up but nothing showed up on my scatter plot. Not sure whats happening.

Best, Ian

I am very new to R and have no programming experience what so ever but I am holding my own for the data analysis we need in my lab. I am detecting changepoints in physiological data using cpt.mean() and until now I have been doing two separate linear regressions with lm() for the data on each side of the changepoint. To make sure the lines connected I was finding the intercept of my two best fit lies and clipping them up to and from their intersection so it was a smooth break point in what looked like a continuous "checkmark" line. At first it worked really well with one study and the intersections were very close to the changepoints cpt.mean() found. Now we are on a study that has data that isn't as clean and the intersection of the two lines is very far from the changepoint. So I thought it would be better to find linear regression lines that anchor to the changepoint. I have read and understand the basic solution to this question here: but I cant seem to figure out how to limit which data it looks at for the linear regression. Normally I do something like this if my changepoint was the 26th data point and I needed to perform a linear regression for only the first 26 data points (PP is my X and MAP is my Y variable):

lm(MAP[1:26]~PP[1:26])

The simple solution to anchoring the best fit line to a specific point,(X0, Y0) was this

lm(I(y-y0)~I(x-x0) + 0)

with my variables:

lm(I(MAP-y0)~I(PP-x0) + 0)

I figured I could just combine the two as follows:

lm(I(MAP[1:26]-y0)~I(PP[1:26]-x0) +0)

No error came up but nothing showed up on my scatter plot. Not sure whats happening.

Best, Ian

This is different, follow up question to someone else's question here:

I am very new to R and have no programming experience what so ever but I am holding my own for the data analysis we need in my lab. I am detecting changepoints in physiological data using cpt.mean() and until now I have been doing two separate linear regressions with lm() for the data on each side of the changepoint. To make sure the lines connected I was finding the intercept of my two best fit lies and clipping them up to and from their intersection so it was a smooth break point in what looked like a continuous "checkmark" line. At first it worked really well with one study and the intersections were very close to the changepoints cpt.mean() found. Now we are on a study that has data that isn't as clean and the intersection of the two lines is very far from the changepoint. So I thought it would be better to find linear regression lines that anchor to the changepoint. I have read and understand the basic solution to this question linked above but I cant seem to figure out how to limit which data it looks at for the linear regression. Normally I do something like this if my changepoint was the 26th data point and I needed to perform a linear regression for only the first 26 data points (PP is my X and MAP is my Y variable):

lm(MAP[1:26]~PP[1:26])

The simple solution to anchoring the best fit line to a specific point,(X0, Y0) was this

lm(I(y-y0)~I(x-x0) + 0)

with my variables:

lm(I(MAP-y0)~I(PP-x0) + 0)

I figured I could just combine the two as follows:

lm(I(MAP[1:26]-y0)~I(PP[1:26]-x0) +0)

No error came up but nothing showed up on my scatter plot. Not sure whats happening.

Best, Ian

Source Link
Ian S
  • 69
  • 1
  • 3
Loading