Sigma Plot, Non-linear regression, fitting a line to a set of points


by dwwhite5150
Tags: baroreflex, line of best fit, non-linear, sigma plot
dwwhite5150
dwwhite5150 is offline
#1
Jan29-13, 04:38 PM
P: 5
I model arterial baroreflex data that I have collected in humans using the Kent equation which is:
y=p1/(1+exp((x-p3)*p2))+p4; where Y=heart rate, X= estimated carotid sinus pressure, p1=range of Y, p2=slope coeff, p3=centerpoint on X, p4 = minimum Y.

I use Sigma Plot to do a best fit line on the points I have collected. The points are actually in six groups of 3 with one point which is the operating point. out of all of those points, the only one i know the gain at for sure is the single operating point.

What I would like to know is: Is there any way to force the best fit line through a point which I have the coordinates and a gain that the line should have while passing through that point.

Attached is a test file graph that explains my problem. the line fits the points with r^2 =0.966 but it does not go through the point (95,70) at a gain of -0.54, which is the only point and gain which is constant. Anybody know how to force fit the line to the point in Sigma Plot?

X Y
175.0000 58.0000 p1= 21.6905
179.0000 59.0000 p2= 0.1047
174.0000 62.0000 p3= 91.5081
155.0000 59.0000 p4= 59.9046
150.0000 57.0000
158.0000 62.0000
135.0000 62.0000
136.0000 63.0000
137.0000 60.0000
114.0000 63.0000
115.0000 59.0000
116.0000 60.0000
95.0000 70.0000
75.0000 78.0000
75.0000 77.0000
74.0000 79.0000
55.0000 83.0000
53.0000 80.0000
59.0000 81.0000
Attached Thumbnails
test curve.png  
Phys.Org News Partner Science news on Phys.org
SensaBubble: It's a bubble, but not as we know it (w/ video)
The hemihelix: Scientists discover a new shape using rubber bands (w/ video)
Microbes provide insights into evolution of human language
DrDu
DrDu is offline
#2
Jan31-13, 09:01 AM
Sci Advisor
P: 3,378
I suppose with gain you mean the slope?
First note that it is not possible to estimate p2 and p3 independently from the data but only the product p5= p2*exp(-p3).
Then when you know dy/dx at some point you can solve this equation for e.g. p1 and eliminate it from the equation which relates y to x, p1, p4 and p5.
dwwhite5150
dwwhite5150 is offline
#3
Jan31-13, 11:19 AM
P: 5
DrDu,
thank you for the reply, I guess what I am really asking is, "In SigmaPlot, Does anybody know how to force an inverse logistic function curve through a known point at a known slope, while fitting the the curve?" the reason I ask is that through manipulation of blood pressure, I get a heart rate response that falls along a curve identified by the equation above, but the only point for which i can calculate the slope is at steady state resting because i have hundreds of small interactions between BP and HR which allow for the dY/dX. the rest of the curve is built with 18 other data points. Just wish I could figure out the syntax for forcing a line through a point at a slope.

DrDu
DrDu is offline
#4
Feb1-13, 03:11 AM
Sci Advisor
P: 3,378

Sigma Plot, Non-linear regression, fitting a line to a set of points


I think I understood your question, although I am not sure whether you understood the solution I was proposing.
I don't know Sigmaplot, but I don't think that's relevant. What you want to do is to find a solution which obeys an auxiliary condition, namely that it's slope at a given point has a given value.
I recommended to include this information explicitly in the equation by elimination of one of the parameters before doing the optimization.
Another method would be to use the technique of Lagrangian multipliers. maybe something of this kind is implemented directly in Sigmaplot.
dwwhite5150
dwwhite5150 is offline
#5
Feb1-13, 07:15 AM
P: 5
DrDu,

You are probably correct in the assumption that I cannot visualize the solution you have given in my mind. Mathematically you suggestions are probably spot on and I will search the SigmaPlot manuals for Lagrangian multipliers and I will also try to eliminate a variable in the equation. As you probably know, some of these statistics programs are touchy and without full knowledge of the syntax, even something as simple in the mind as "Hey, go through this point at this slope while fitting the line," becomes terribly difficult.

If you happen to run across the syntax solution to force fit a line, let me know. Even if you find it in some other computer program, it can probably be translated to SigmaPlot.

Again, thank you for all of your insight, it has given me tons to consider for future data analysis. If I use your suggestions, I will include you in the acknowledgements section of my dissertation and any other publications that come.
rollingstein
rollingstein is offline
#6
Feb1-13, 07:22 AM
P: 305
Quote Quote by DrDu View Post
I think I understood your question, although I am not sure whether you understood the solution I was proposing.
I don't know Sigmaplot, but I don't think that's relevant. What you want to do is to find a solution which obeys an auxiliary condition, namely that it's slope at a given point has a given value.
I recommended to include this information explicitly in the equation by elimination of one of the parameters before doing the optimization.
Another method would be to use the technique of Lagrangian multipliers. maybe something of this kind is implemented directly in Sigmaplot.
So far as I know, this cannot be done in Sigmaplot.
rollingstein
rollingstein is offline
#7
Feb1-13, 07:39 AM
P: 305
Add this as your constraint by setting RHS to -0.54 at x=95:

rollingstein
rollingstein is offline
#8
Feb1-13, 08:26 AM
P: 305
Actually the slope and pass-through-point constraint give you two independant eq. in (p1, p2, p3, p4).

Using algebra, can't you restate the model in just 2 variable and then use the fit function?

Do you see what I mean?

The algebra seems a bit messy for the slope constraint though.

i.e.

p4=70-p1/(1+exp((95-p3)*p2))

and

p1={ 0.54*[exp(p2*p3)+exp(p2*95)]^2 } / {p2 * exp(p2*(p3 + 95)) }

So now fit in SigmaPlot the following fn but only for p2 and p3.

y=[{ 0.54*[exp(p2*p3)+exp(p2*95)]^2 } / {p2 * exp(p2*(p3 + 95)) }]/(1+exp((x-p3)*p2))+70-p1/(1+exp((95-p3)*p2))

Messy, but you put the constraints on and not me. :)
dwwhite5150
dwwhite5150 is offline
#9
Feb1-13, 08:41 AM
P: 5
rollingstein,

thanks for the reply. I tried putting the solution that you gave as a constraint but i got an error message. I am assuming that it is a parenthetical problem so i put it into excel and the slope I get back while putting in the parameters 1.6*10^-74. It is probably something that I did wrong. you seem to have some experience with sigmaplot. how would you type the equation into the constraint section?
rollingstein
rollingstein is offline
#10
Feb1-13, 09:03 AM
P: 305
Quote Quote by dwwhite5150 View Post
rollingstein,

thanks for the reply. I tried putting the solution that you gave as a constraint but i got an error message. I am assuming that it is a parenthetical problem so i put it into excel and the slope I get back while putting in the parameters 1.6*10^-74. It is probably something that I did wrong. you seem to have some experience with sigmaplot. how would you type the equation into the constraint section?
Its likely I did an algebra blunder. Verify my rearrangements.
rollingstein
rollingstein is offline
#11
Feb1-13, 10:33 AM
P: 305
The red line looks right?



Larger image here:

http://i.imgur.com/qoxSAo8.jpg

Verification:

predict(fit1,list(x=95))
[1] 70

(predict(fit1,list(x=96))-predict(fit1,list(x=94)))/(96-94)
[1] -0.5395504

PS. I used R instead; didn't have Sigmaplot handy.
rollingstein
rollingstein is offline
#12
Feb1-13, 10:43 AM
P: 305
Quote Quote by rollingstein View Post
Its likely I did an algebra blunder. Verify my rearrangements.

It was a mistake. Left a p1 unsubstituted.

Try fitting this in Sigmaplot for p2 and p3.:

y=(( 0.54*(exp(p2*p3)+exp(p2*95))^2 ) / (p2 * exp(p2*(p3 + 95)) ))/(1+exp((x-p3)*p2))+70-(( 0.54*(exp(p2*p3)+exp(p2*95))^2 ) / (p2 * exp(p2*(p3 + 95)) ))/(1+exp((95-p3)*p2))
dwwhite5150
dwwhite5150 is offline
#13
Feb1-13, 11:19 AM
P: 5
Rollingstein,

That's pretty awesome, still can't get sigmaplot to accept the equations as fitting constraints. also I have to make the equations dynamic because p1, p2, p3, p4, OP(x,y), m(OP) change for every subject. OP is the operating point for which I have the point and slope. I have sent in a request to systat for them to make "force fitting a line" a drop down option in the regression wizard. Thanks for all the work you have put in to this. I will keep trying to finesse the equations into existence but it may be a never-ending struggle with SigmaPlot.

Thanks alot dude
rollingstein
rollingstein is offline
#14
Feb1-13, 11:21 AM
P: 305
Quote Quote by dwwhite5150 View Post
Rollingstein,

That's pretty awesome, still can't get sigmaplot to accept the equations as fitting constraints. also I have to make the equations dynamic because p1, p2, p3, p4, OP(x,y), m(OP) change for every subject. OP is the operating point for which I have the point and slope. I have sent in a request to systat for them to make "force fitting a line" a drop down option in the regression wizard. Thanks for all the work you have put in to this. I will keep trying to finesse the equations into existence but it may be a never-ending struggle with SigmaPlot.

Thanks alot dude
Sure. It was an interesting problem; hence my motivation. :)


Try R:

fit<-nls(y~p1/(1+exp((x-p3)*p2))+p4,start=list(p1=20,p2=0.1,p3=90,p4=50))
 summary(fit)

  plot(x,y)
  
  tt<-seq(60,180,length=100)
  
  lines(tt, predict(fit,list(x=tt)))
  
  
fit1<-nls(y~(( 0.54*(exp(p2*p3)+exp(p2*95))^2 ) / (p2 * exp(p2*(p3 + 95)) ))/(1+exp((x-p3)*p2))+70-(( 0.54*(exp(p2*p3)+exp(p2*95))^2 ) / (p2 * exp(p2*(p3 + 95)) ))/(1+exp((95-p3)*p2)),start=list(p2=0.1,p3=90))

lines(tt, predict(fit1,list(x=tt)),col=34)

predict(fit1,list(x=95))
[1] 70

(predict(fit1,list(x=96))-predict(fit1,list(x=94)))/(96-94)
[1] -0.5395504
rollingstein
rollingstein is offline
#15
Feb1-13, 11:25 AM
P: 305
Quote Quote by dwwhite5150 View Post
Rollingstein,

also I have to make the equations dynamic because p1, p2, p3, p4, OP(x,y), m(OP) change for every subject. OP is the operating point for which I have the point and slope.

I think the current formulation is pretty dynamic. Just replace 95 by x_OP,70 by y_OP and -0.54 by s_OP

The rest should be the same.

I'm telling you, it'll be a breeze in R.

PS. I'm no R loyalist. I believe in whatever works. Had tried Python on your problem at first but didn't get far.


Register to reply

Related Discussions
Fitting a curve in log-linear plot. General Math 6
Coefficient of Determination in case of repeat points, in linear regression Set Theory, Logic, Probability, Statistics 3
Matlab, fit custom regression line to data points Math & Science Software 0
Returning each co-ord between two points of a linear line Calculus & Beyond Homework 1
Fitting points from a straight line segment onto a circular segment Programming & Computer Science 3