[R] Vectors with equal sd but different slope

Greg Snow Greg.Snow at imail.org
Fri Jan 29 21:34:19 CET 2010


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,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of syrvn
> Sent: Friday, January 29, 2010 8:09 AM
> To: r-help at r-project.org
> Subject: [R] Vectors with equal sd but different slope
> 
> 
> 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
> --
> View this message in context: http://n4.nabble.com/Vectors-with-equal-
> sd-but-different-slope-tp1415562p1415562.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list