forcing a line in a scatterplot that shows what a given correlation would be

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

forcing a line in a scatterplot that shows what a given correlation would be

Art Kendall
In policy work it is important to compare obtained results to some criterion of practical significance.
In other words, does the correlation reach the criterion for practical utility of .25.
For example, the example syntax below generate a statistically significant but practically trivial correlation of .106.

I am trying to adopt the following syntax to demonstrate on a scatter plot 3 lines.
1) line for the obtained correlation
2) line at the mean of y for zero correlation
3) a line for a minimum correlation for practical utility.

How can I get a) the third line
b) different line styles
c) possibly a legend labeled
 Obtained r
 Zero r
 Criterion r?

Art Kendall
Social Research Consultants

*based on syntax to generate data with a given correlation and specific range
* courtesy of Ryan Black 1/15/2011.

*Generate data.
*change seed until you get close enough to target correlation[AJK].
set seed 79501011.
new file.
inp pro.
loop ID= 1 to 1700.
    comp correlation=.10.
    comp X = rv.normal(0,1).
    comp rawY = rv.normal(0,1).
    comp Y=X * correlation + RawY * (1 - correlation**2)**.5.
    end case.
  end loop.
end file.
end inp pro.
exe.

*Obtain minimum and maximum values of X and Y.
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /X_max=MAX(X)
  /X_min=MIN(X)
  /Y_max=MAX(Y)
  /Y_min=MIN(Y).

*Normalize data such that X and Y values range from 1 to 5.
comp X = 1 + ((X - X_min)  * (5 -1)) / (X_max - X_min).
comp Y = 1 + ((Y - Y_min)  * (5 -1)) / (Y_max - Y_min).
execute.

DELETE VARIABLES ID correlation RawY X_max X_min Y_max Y_min.

*Compute r.
CORRELATIONS
  /VARIABLES=X with Y/statistics= descriptives
  /PRINT=TWOTAIL NOSIG.

*[AJK].
* Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=X Y MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: X=col(source(s), name("X"))
  DATA: Y=col(source(s), name("Y"))
  GUIDE: axis(dim(1), label("X"))
  GUIDE: axis(dim(2), label("Y"))
  ELEMENT: point.jitter(position(X*Y))
  ELEMENT: line(position(smooth.linear(X*Y)))
  ELEMENT: line(position(smooth.mean.uniform(X*Y)))
  TRANS: Y = eval(sin(.25)*cos(.25)*(X-5))
  ELEMENT: line(position(smooth.linear(X*Y)))
END GPL.


===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants