Skip to content

Vectors with equal sd but different slope

3 messages · syrvn, Amy Hessen, Greg Snow

#
Hi,

what I would need are 2 vector pairs (x,y) and (x1,y1). x and x1 must have
the same sd. y and y1 should also exhibit the same sd's but different ones
as x and x1. Plotting x,y and x1,y1 should produce a plot with 2 vectors
having a different slope. Plotting both vector pairs in one plot with fixed
axes should reveal the different slope.


many thanks
syrvn
#
Here is one approach:

library(MASS)

cor1 <- diag(2)
cor1[1,2] <- cor1[2,1] <- 0.5

cor2 <- cor1
cor2[1,2] <- cor2[2,1] <- 0.9

sd <- c(5,20)
mns <- c(50, 100)

cov1 <- diag(sd) %*% cor1 %*% diag(sd)
cov2 <- diag(sd) %*% cor2 %*% diag(sd)

one <- mvrnorm(100, mns, cov1, empirical=TRUE)
two <- mvrnorm(100, mns, cov2, empirical=TRUE)

cor(one)
cor(two)
apply(one,2,mean)
apply(two,2,mean)
apply(one,2,sd)
apply(two,2,sd)

plot(one, col='blue')
points(two, col='green')
abline( lm(one[,2] ~ one[,1]), col='blue' )
abline( lm(two[,2] ~ two[,1]), col='green' )


You can modify values to fit your situation better.

Hope this helps,