Statisics - linearity and best-fit in 3 dimensions

In summary, the conversation revolves around a problem of detecting gestures using a set of 3D data points (x, y, and z values) that are ordered in time. The main goal is to determine if the data points fall on a line, with some suggestions of using Pearson's R test twice or fitting a line through the data points using linear regression. However, it is mentioned that the best approach may be subjective and dependent on the evaluator or the specific problem at hand. It is also suggested to consult relevant literature or experts in the field for guidance.
  • #1
jamesson
59
3
Howdy folks

I've gotten a number of answers to this in various fora, some contradictory.

I need to do 3 things to a set of datapoints in 3space (X,y, and z real values).

1)Test for linearity (pearson's R?).

2)If passed, find line of best fit (SSE?)

3)See if line of best fir is near parallel to any of the axes (Slope < whatever or > whatever?)

Some have said that I can simply do pearson's r twice, but others have disagreed without providing a counterargument.

If possible, please give equations or expressions.

Many thanks in advance for any assistance

Joe
 
Physics news on Phys.org
  • #2
You could find the line of best fit first and then transform coordinates so that line is in a plane and use Pearson's R to test for linearity in the transformed coordinate system by projecting the data points onto that plane in various ways.

Saying that you apply Pearson's R to 3 dimensional data is ambiguous until you specify exactly how that would be done. Are you talking about something like dropping the y values and applying it only the (z,x) data?
 
  • #3
The proposed solution was to use pearson's r twice, once for xz and once for xy. If that's what you meant by dropping one of the variables, then yes, you are correct. However, some pretty advanced people said this would not work. They did not say why.
 
  • #4
Let's clarify whether you are trying to do "linear regression" on the data or whether you are fitting a "line" to it. The usual kind of linear regression fits a plane to 3D data.
 
  • #5
I am trying to fit a line, not a plane.
 
  • #6
Let me make sure I understand that!

Can I assume one variable is to be predicted from the other two?

Let's say we are trying to predict z. An equation of the form z = Ax + By + C defines a plane. If you are trying to use a line to predict z then it would have the form z = Aw + C where w is some variable. What variable did you have in mind for w?
 
  • #7
Well to be honest I'm not trying to predict anything. Rather I need to see if these datapoints fall on a line for gesture detection. That said, I _think_ anything that predicts Z would work.
 
  • #8
Wouldn't the intersection of 2 planes be a line? Therefore wouldn't two linear regrssions work as I was told?
 
  • #9
jamesson said:
Wouldn't the intersection of 2 planes be a line? Therefore wouldn't two linear regrssions work as I was told?

Two planes can intersect to form a line. However, z = Ax + B defines a line in the zx plane and z = Cy + D defines a line in zy plane. The zx plane and the zy plane intersect at the z-axis, which is probably not what you had in mind. So you need to explain what you mean by "two linear regressions".

Are you talking about predicting y as y = Ax + B and then predicting z as z = Cy + D and then assuming y can be replaced by Ax + B, so the prediction becomes z = C(Ax + B) + D ? If so, I can see why some people might say to do two Pearson's R tests. Whether you ought to use this approach is unclear.Applying statistics to real world problems is a subjective matter. In the type of statistics you want to use ("frequentist") , methods are selected according to people's empirical experience, tastes and traditions. If you are writing a thesis or journal article, the best thing to do is to consult the people who are evaluating your work about what statistical methods may be used. If you can't do that, look at examples of publications that they have approved.

If you are trying to solve a real world problem, I think you'll get the best advice by describing the problem, not by merely attempting to abstract the mathematical details yourself.

Edit: Sorry, I only read your last post and didn't read the one before. You did describe a real world problem. Do (x,y,z) describe the positions of the thing that makes the gesture. Is this data ordered in time?
 
Last edited:
  • #10
Yes x,y,z are ordered in time. I need to determine if they fall on a line to initiate gesture detection.
 
  • #11
OK, regarding your original question:

I need to do 3 things to a set of datapoints in 3space (X,y, and z real values).

Do those 3 things really define your goal? - i.e. are you determined to approach the problem that way?

Or is the bottom line description of your goal something like: I want to detect if the path of an object in space determines a gesture indicating a direction and if it does, then I want to determine that direction.

Questions such as whether you can use Pearson's R test twice etc in this problem are going to be empirical questions not questions that have definite mathematically provable answers - unless you are the type of person who is willing to supply enough "givens" for mathematics to work with. You could supply the "givens" by supplying a detailed probablity model for how the data is produced. For one reason or another, most people with real world problems don't do that.

The advice about consulting the evaluators still holds if this work is to be written up as an article or a thesis or "defended" in some manner. (For example, there are many papers written on gesture detection. Evaluators would compare how you did it to the methods in such papers.. If you are writing a computer program under a software contract, you may be asked to show that you exercised "due diligence" in consulting such literature.)

If doing this work just for your own purposes, you can obviously try any method that you want I wouldn't say that doing two Pearson's R tests is patently absurd as an empirical approach. However, I wouldn't guarantee that it would work well either.

There is a type of regression called "total least squares" regression. For example, if you assume the data is generated by some random displacement from a line, then express the line in parametric form as (x,y,z) = (As+B,Cs+D,Es+F) where s is an arbitrary parmeter. Find the values of the constants that minimize sum of the squares of the distances from each data point to the line. As I recall, that algorithm is more involved than doing two linear regressions. The variable s need not be time. For example, you could use x for s.

If I think of how human beings gesture, they might extend and retract their arm several times to indicate a direction. Is this back-and-forth kind of gesture among those you are trying to detect?
 
  • #12
re, back and forth, no, quite the contrary. I have a package that detects an arbitrary gesture in 2-space (and can learn new gestures) and a package that tracks joints of the human body in 3space. However, the function of the gesture detection package is predicated on an "init event" (originally mousedown) and a "stop event" (mouseup). In my environment I need to build an init event from scratch. The simplest solution I could come up with is to detect individual motions parallel to the axes (over a limited set of datapoints), then use start and end end points to determine direction
 
  • #13
I don't know how you define a "gesture". You say you are using a software package to track the motions of human joints. Are you tracking the motion of knee joints or other joints that I don't usually associate with making a "gesture" in the common meaning of that word. Or are you only tracking the motion of one joint, such as the wrist joint or index finger joint?

Let me see if I understand the purpose of the algorithm you want to write.
The input is a record of 3D (x,y,z,t) data of a single joint. The algoirthm detects when it makes a linear motion. When the motion occurs, the algorithm determines "init" and "stop" times of the (x,y,z) data and sends this as input to the 2-D gesture detection software. But won't you have to project the (x,y,z) data onto 2-D in order to used that software?
 
  • #14
Nope. Between init and stop the user knows to make a 2d gesture and the zplane data is discarded for those purposes. Re joint types, the software doesn't make that distinction - gesture handling is the same for all joints. I can inspect output to see what made the gesture but the gesture handler is common.
 
  • #15
You avoided explaining what a gesture is! Is it any linear movement of a joint?

It would be convenient if you would give a precise and complete description of the problem. What is the final goal of this process? How do you determine how well your procedure works?

For now, let me guess. I'll guess that in terms of a video, the z direction is the direction the camera is looking. Suppose we are tracking a wrist joint and the person swings his outstretched arm in a circle. From some points of view, his wrist swings in an arc, but from other special points of view, his wrist would move in a line. So you want to apply some algorithm to the estimated 3D positions of a joint to determine if a set of 3D positions are approximately a line (as opposed to non-linear motion that just happens to project to a line in (x,y) ) before you send the 2D data to the gesture detection software.
 
  • #16
A gesture is an arbitrary set of time-tagged data on the xy plane (x, y, t). An init or stop is a dataset of consisting of a straight (for some value of straight) line parallel to any axis on any plane (x, y, z, t). It would be nice if I could tell one init or stop from another, by selecting what axis it is parallel to and whether it's coming or going, but I'll be happy enough with detecting a "straight" line parallel to the xz axis.

Your understanding of the coordinate system is on the money, and so is your general analysis of the problem. Final goal is to initiate gathering of data for 2d gesture detection by detecting outward horizontal or vertical linear motion (away from origin) along one of the 6 axes and perform gesture detection on collected data triggered by inward horizontal or vertical linear motion (towards origin). If I was drawing on a screen with a mouse, outward linear motion would be a mousedown (press the mouse button) and inward would be mouseup (release mouse button)

It's nice to see somebody actually caring about the problem as opposed to the math. Thanks again for all your help.

Joe

Sorry if this feels like pulling teeth, it's difficult to separate my knowledge of the system form common factors of a 3d space.
 
Last edited:
  • #17
You've mentioned looking for motion parallel to "any axis". Let's clarify that. Assume z is "into the picture", x is "up" and y is "horizontal". (I count this as 3 axes, not six since I don't count the negative x axists as different from the positive x axis. Suppose a joint makes a straight line motion in the xy plane at a 45 degree angle to the postitive y axis. You could say that motion is parallel to a tilted axis, but it isn't parallel to the x or y axis. Are you interested in that type of linear motion?

You also mention motion being toward or away from "the origin". Suppose the video shows a person standing with their feet at the origin and the motion data is for the motion of their wrist as they make various gestures like football referees so. Are you looking for motions that go straight toward or away from their feet? Or does "the origin" mean something different than the origin of the coordinate system?
 
  • #18
No, I am not interested in motion parallel to a tilted axis. Your understanding of my use of origin is also I think correct - in fact one operating mode of the gesture-tracking package specifically locks the coordinate system to body centroid and calculates all distances from there. So, to be absolutely accurate, origin should not be the feet but around waist level. However, a better solution would set origin from initial joint position - therefore, for any joint origin is set to first detected position in world coordinate system. This is again wishful thinking - if it overcomplicates the problem by all means pick a set origin around waist/navel level and go from there.
 
Last edited:
  • #19
I'm having a hard time visualizing any practical problem where one would only care about motion parallel to one of the coordinate axes!

In an earlier post, you said
The simplest solution I could come up with is to detect individual motions parallel to the axes (over a limited set of datapoints), then use start and end end points to determine direction

Is the direction that is determined by the start and end points always to be a direction that is parallel to one of the coordinate axes?
 
  • #20
Well, after we have tested to see if they are indeed parallel then yes. In that post by direction I meant towards or away from origin. Sorry if that was unclear

Re application, think of a mouse or a keyboard. A "click" or "keystroke" only "moves" in one direction. Think of the 6 possible motions (3 axes, 2 directions) as 6 keystrokes. As I said, the 2d recognizer requires an init event to begin gathering data for recognition. The parallel motions will serve as init events.
 
Last edited:
  • #21
I'd say using Pearson's r is not a good idea, for example, if a line is parallel to one of the axis you use to calculate it the correlation will be zero.

A PCA answers all your three questions at once, if it is a line you will have only one significant eigenvalue and its eigenvector will tell you if its parallel or not to any axis.

For more info:
http://en.wikipedia.org/wiki/Principal_component_analysis
 
Last edited:
  • #22
I have had pca suggested to me before. Could you please give an expression involving sums but not integrals or derivative, as the environment I'm working with does not support them? I have been unable to make my way through the wiki article (freshman calc etc).

Also, apologies in advance if this involves matrices and I ask some rookie questions - my matrix skills are kinda weak.

Thanks again

Joe
 
  • #23
jamesson said:
Re application, think of a mouse or a keyboard. A "click" or "keystroke" only "moves" in one direction. Think of the 6 possible motions (3 axes, 2 directions) as 6 keystrokes.

OK, I'm going to think of someone giving hand signals to an equipment operator. The one's you want to recognize are left, right, up, down, forward , backward.

The way I'm visualizing the data at present is that you not only have the problem of applying some test to a set of data, you have the problem of picking which sets of data to analyze. If I think of the data as a long series of vectors (x1,y1,z1,t1), (x2,y2,z2,t2)...(xn,yn,zn,tn) then this sequence may contain several different gestures. So you must picked out various "windows" of data to analyze. The data from t10 to t200 might be one gesture and the data from t315 to t390 might be another. Am I correct that picking out sequences of data is part of the problem? Have you solved that part of it already?

Should we think of this as a non-real time system where we can scan back and forth in all the data? Or must the system work in roughly real time as data is coming in?
 
  • #24
Your concept of "hand signals" is accurate, however selection of windows (if I understand you correctly) is inherently not part of the problem. Once an "init" "hand signal" is received we assume that whatever follows is a 2d gesture. All 2d gestures consist of an arbitrary (but equal) number of datapoints which are compared to a prerecorded library of gestures in realtime. The software then identifies the gesture (there is a tolerance value which tells the software how closely the input gesture must match the recorded gesture). Recording of 2d data continues until the "stop" "hand signal" is received. The "stop" "hand signal" is nothing more than the "init" "hand signal" reversed; that is to say whereas The "begin gesture" (init) "hand signal" moves away from the origin, the "stop" "hand signal" moves toward the origin along the same axis as the "init". When "stop" is received any points beyond the arbitrary preset length are discarded and 2d recognition occurs. I am not yet 100% sure I will need a stop (I may simply trigger recognition when the requisite number of points is received) but far easier to build it and not use it than try to build it later.

Example;

1) user moves hand up
2) 2d datapoint recording begins on the xz plane
3) user moves hand down or requisite length of xz dataset is reached
4) recognition occurred, result is handled, gesture listener resets.

Re realtime, most definitely realtim

Thanks again
 
  • #25
jamesson said:
I have had pca suggested to me before. Could you please give an expression involving sums but not integrals or derivative, as the environment I'm working with does not support them?...

Joe

What is that environment?
 
  • #26
Max MSP
 
  • #27
the tutorial article wikipedial links to is actually far ,ore soothing than wikipedia itself. I may give it a shot later tonight.
 
  • #28
jamesson said:
Max MSP

Oh I see, about music?, OK, obviously your best choice would be to find some libraries that you might use from Max MSP to calculate the PCA, but if that is not an option, I would say that the chapter Computing principal components efficiently in the wiki link is pretty much what you need. It gives you a way to calculate the PCA with an iterative computation which only uses products and sums. And in your case you don't even need to calculate all eigenvalues and vectors.

I'm sure Max MSP should be able to deal with that one...

Good luck though!
 
  • #29
Don't know when I will get to try this way, but hopefully soon, and I definitely will need help. Thanks again.
 
  • #30
jamesson said:
Don't know when I will get to try this way, but hopefully soon, and I definitely will need help. Thanks again.

You're welcome, but hey, post a video with this project, it looks pretty interesting!
 
  • #31
Let's discuss an utterly simple method. Perhaps objections to it will clarify the problem further.

Let the data points be [itex](x_i,y_i,z_i,t_i) [/itex] for [itex] i = 1 [/itex] to [itex] N [/itex]. If this data represented a line perfectly parallel to the y-axis then the [itex] x [/itex] and [itex] z [/itex] values would remain constant while the [itex] y [/itex] value varied.

If we have data from an imperfect line, we could estimate the line that the data is "trying to" follow in various ways. The simplest seems to be to estimate that the [itex] \hat{x} = [/itex] the average of the [itex] x [/itex] values in the data and [itex] \hat{z} = [/itex] the average of the [itex] z [/itex] values.

We can quantify the "error" that the imperfect data has in various ways. The one that comes to my mind first

[tex] \hat{\sigma^2} = (\frac{1}{N}) { \sum_{i=1}^N ( (\hat{x} - x )^2 + (\hat{z}-z)^2)} [/tex]

Of course the idea is to classify the data as a gesture parallel to the y-axis when [itex] \hat{\sigma^2} [/itex] is "small". What constitutes a small or large error would have to be determined empirically. You'd have to do a different test for each axis, but this is not an elaborate computation.

One weakness of this method is that it doesn't give any more credit to data that is a perfect straight line but slightly out-of-parallel vs data that is scattered. Is this weakness the reason that you are considering sophisticated statistical methods?
 

1. What is linearity in statistics?

Linearity in statistics refers to the relationship between two variables that can be represented by a straight line on a graph. This means that as one variable increases, the other variable also increases or decreases at a constant rate. Linearity is an important concept in statistics as it allows us to make predictions and draw conclusions based on the relationship between variables.

2. How is linearity tested in statistics?

Linearity can be tested in statistics by creating a scatter plot of the data and visually inspecting if the points fall along a straight line. Additionally, statistical tests such as the Pearson correlation coefficient or the coefficient of determination can be used to quantify the degree of linearity between two variables.

3. What is a best-fit line in 3 dimensions?

A best-fit line in 3 dimensions is a line that represents the relationship between three variables in a three-dimensional space. It is the line that minimizes the distance between the data points and the line, and is used to make predictions and draw conclusions about the relationship between the variables.

4. How is a best-fit line calculated in 3 dimensions?

A best-fit line in 3 dimensions is calculated using a statistical method called linear regression. This method involves finding the equation of the line that minimizes the sum of the squared distances between the data points and the line. This equation can then be used to make predictions and draw conclusions about the relationship between the variables.

5. What is the significance of linearity and best-fit in 3 dimensions?

Linearity and best-fit in 3 dimensions allow us to understand and quantify the relationship between multiple variables. This is important in many fields of science, such as economics, engineering, and biology, where multiple factors can influence an outcome. By understanding the linearity and best-fit in 3 dimensions, we can make more accurate predictions and draw meaningful conclusions from our data.

Similar threads

Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
10K
  • Precalculus Mathematics Homework Help
Replies
3
Views
3K
  • Precalculus Mathematics Homework Help
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Back
Top