0
votes

I have two vectors of real values and estimated values with the same length. I want to see dependence between 2 variables. It seems scatter plot is suitable for this purpose. So, I have two questions:

  1. What is the best method to represent the dependence between my vectors?
  2. How to find the trend line or the best fit line?

I use scatter(A,B) but how to find the trend line or the best fit line?

Thanks.

scatter plot

1
If A and B are vectors of equal length, I would simply use plot(A,B,'.') to get the cloud of points - Luis Mendo
@Thanks but I want to find the best fit line or trend line. - Fatime
For fitting a (stright) line, have you taken a look at polyfit? (with a polynomial of order 1) - Luis Mendo
@LuisMendo Yes, but I'm not sure about the results. - Fatime

1 Answers

2
votes

The best way to compare two different groups is using analysis of variance. Analysis of variance (ANOVA) is a collection of statistical models used to analyze the differences between group means and their associated procedures (such as "variation" among and between groups). You should use ANOVA. also there are some functions included in MATLAB like: anova1, ...

p = anova1(X,group)

The standard ANOVA table divides the variability of the data into two parts:

1- Variability due to the differences among the column means (variability between groups) 2- Variability due to the differences between the data in each column and the column mean (variability within groups)

Example 1 (from mathworks) Create X with columns that are constants plus random normal disturbances with mean zero and standard deviation one:

X = meshgrid(1:5)
X =
   1   2   3   4   5
   1   2   3   4   5
   1   2   3   4   5
   1   2   3   4   5
   1   2   3   4   5

X = X + normrnd(0,1,5,5)
X =
    1.3550    2.0662    2.4688    5.9447    5.4897
    2.0693    1.7611    1.4864    4.8826    6.3222
    2.1919    0.7276    3.1905    4.8768    4.6841
    2.7620    1.8179    3.9506    4.4678    4.9291
   -0.3626    1.1685    3.5742    2.1945    5.9465

Perform one-way ANOVA:

p = anova1(X)
p =
  7.9370e-006

You can see the anova table:

enter image description here

and also a box-plot related to the analysis:

enter image description here

There are of course more function in MATLAB that you can check.

Actually I don't get the meaning of your image, you can easily add the line after plotting the scatter. using 'hold on' command.

Check these links for more information and examples. link - 1 link - 2 link - 3