Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

16.5.2 BRugs: Robust Linear Regression > 16.5.2 BRugs: Robust Linear Regression - Pg. 439

16.5 R Code 439 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 HtFmu2 = 64.36 HtFsd2 = 2.49 lnWtFmu2 = 4.86 lnWtFsd2 = 0.14 Frho2 = 0.44 prop2 = 1 - prop1 Fmean2 = c( HtFmu2 , lnWtFmu2 ) Fsigma2 = matrix( c( HtFsd2^2 , Frho2 * HtFsd2 * lnWtFsd2 , Frho2 * HtFsd2 * lnWtFsd2 , lnWtFsd2^2 ) , nrow = 2 ) # Randomly generate data values from those MVN distributions. if ( !is.null( rndsd ) ) { set.seed( rndsd ) } datamatrix = matrix( 0 , nrow = nSubj , ncol = 3 ) colnames(datamatrix) = c( "male" , "height" , "weight" ) maleval = 1 ; femaleval = 0 # arbitrary coding values for ( i in 1:nSubj ) { # Flip coin to decide sex sex = sample( c(maleval,femaleval) , size = 1 , replace = TRUE , prob = c(.5,.5) ) if ( sex == maleval ) { datum = mvrnorm(n = 1, mu = Mmean, Sigma = Msigma ) } if ( sex == femaleval ) { Fclust = sample( c(1,2) , size = 1 , replace = TRUE , prob = c(prop1,prop2) ) if ( Fclust == 1 ) { datum = mvrnorm(n = 1, mu = Fmean1, Sigma = Fsigma1 ) } == = = = =