Library: | graphic |
See also: | svd grandrews grpcp grstar grsurface |
Quantlet: | grbiplot | |
Description: | Generates a graphical object containing the coordinates for the biplot of a given matrix. |
Usage: | b = grbiplot(x,r,k) | |
Input: | ||
x | n x p matrix, data (n >= p) | |
r | scalar, rank of approximation (r <= p) | |
k | scalar, 0 <= k <= 1 | |
Output: | ||
b | (n+p) x r matrix, containing the coordinates for the biplot |
a = u_1 * l_1^k ~ u_2 * l_2^k ~ ... ~u_r * l_r^k
b = v_1 * l_1^(1-k) ~ v_2 * l_2^(1-k) ~ ... ~v_r * l_r^(1-k)
u_i = left eigenvectors of x
v_i = right eigenvectors of x
l_i = eigenvalues of x
with: 0<=k<=1 and r<=p
r is the rank of approximation.
The vectors in the rows of a are used to plot the coordinates of the n cases, and the rows of b are the coordinates for plotting the p variables. x must be a n x p matrix.
library("graphic") x = read("uscrime") ;; read US crime data x=x[,3:(cols(x)-2)] n = rows(x) b = grbiplot(x, 2, 0.5) ;; create biplot graphical object dat1 = b[1:n] dat2 = b[(n+1):rows(b)] d = createdisplay(1,1) xrows= "ME"|"NH"|"VT"|"MA"|"RI"|"CT"|"NY"|"NJ"|"PA"|"OH"|"IN"|"IL"|"MI" xrows = xrows|"WI"|"MN"|"IA"|"MO"|"ND"|"SD"|"NE"|"KS"|"DE"|"MD" xrows = xrows|"VA"|"WV"|"NC"|"SC"|"GA"|"FL"|"KY"|"TN"|"AL"|"MS"|"AR"|"LA"|"OK" xrows = xrows|"TX"|"MT"|"ID"|"WY"|"CO"|"NM"|"AZ"|"UT"|"NV"|"WA"|"OR"|"CA"|"AK"|"HI" setmaskt(dat1,xrows,1,0,15) xcols="mur"|"rap"|"rob"|"ass"|"bur"|"lar"|"aut" setmaskp(dat1,0,0,0) setmaskt(dat2,xcols,4,0,15) setmaskp(dat2,0,0,0) show(d,1,1,dat1, dat2)
shows a biplot of the US crime data. The states are labeled in blue the crime type is labeled in red