R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("polycor-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('polycor') Loading required package: mvtnorm > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "hetcor" > > ### * hetcor > > flush(stderr()); flush(stdout()) > > ### Name: hetcor > ### Title: Heterogeneous Correlation Matrix > ### Aliases: hetcor hetcor.default hetcor.data.frame print.hetcor > ### as.matrix.hetcor > ### Keywords: models > > ### ** Examples > > R <- matrix(0, 4, 4) > R[upper.tri(R)] <- runif(6) > diag(R) <- 1 > R <- cov2cor(t(R) %*% R) > round(R, 4) # population correlations [,1] [,2] [,3] [,4] [1,] 1.0000 0.2566 0.3073 0.5555 [2,] 0.2566 1.0000 0.5360 0.2618 [3,] 0.3073 0.5360 1.0000 0.6828 [4,] 0.5555 0.2618 0.6828 1.0000 > data <- rmvnorm(1000, rep(0, 4), R) > round(cor(data), 4) # sample correlations [,1] [,2] [,3] [,4] [1,] 1.0000 0.2762 0.3585 0.5849 [2,] 0.2762 1.0000 0.5610 0.2877 [3,] 0.3585 0.5610 1.0000 0.6969 [4,] 0.5849 0.2877 0.6969 1.0000 > x1 <- data[,1] > x2 <- data[,2] > y1 <- cut(data[,3], c(-Inf, .75, Inf)) > y2 <- cut(data[,4], c(-Inf, -1, .5, 1.5, Inf)) > data <- data.frame(x1, x2, y1, y2) > hetcor(data) # Pearson, polychoric, and polyserial correlations, 2-step est. Two-Step Estimates Correlations/Type of Correlation: x1 x2 y1 y2 x1 1 Pearson Polyserial Polyserial x2 0.2762 1 Polyserial Polyserial y1 0.3223 0.5577 1 Polychoric y2 0.569 0.3062 0.6394 1 Standard Errors: x1 x2 y1 x1 x2 0.02923 y1 0.04002 0.03143 y2 0.02181 0.03021 0.03115 n = 1000 P-values for Tests of Bivariate Normality: x1 x2 y1 x1 x2 0.9026 y1 0.06288 0.8612 y2 0.7008 0.8767 0.2098 > hetcor(x1, x2, y1, y2, ML=TRUE) # Pearson, polychoric, polyserial correlations, ML est. Maximum-Likelihood Estimates Correlations/Type of Correlation: x1 x2 y1 y2 x1 1 Pearson Polyserial Polyserial x2 0.2762 1 Polyserial Polyserial y1 0.3221 0.5575 1 Polychoric y2 0.5696 0.3067 0.6394 1 Standard Errors: x1 x2 y1 x1 x2 0.02923 y1 0.04008 0.03152 y2 0.02241 0.03056 0.0323 n = 1000 P-values for Tests of Bivariate Normality: x1 x2 y1 x1 x2 0.9026 y1 0.05947 0.863 y2 0.7036 0.8861 0.2112 > > > > cleanEx(); ..nameEx <- "polychor" > > ### * polychor > > flush(stderr()); flush(stdout()) > > ### Name: polychor > ### Title: Polychoric Correlation > ### Aliases: polychor > ### Keywords: models > > ### ** Examples > > data <- rmvnorm(1000, c(0, 0), matrix(c(1, .5, .5, 1), 2, 2)) > x <- data[,1] > y <- data[,2] > cor(x, y) # sample correlation [1] 0.50479 > x <- cut(x, c(-Inf, .75, Inf)) > y <- cut(y, c(-Inf, -1, .5, 1.5, Inf)) > polychor(x, y) # 2-step estimate [1] 0.4401632 > polychor(x, y, ML=TRUE, std.err=TRUE) # ML estimate Polychoric Correlation, ML est. = 0.4401 (0.04075) Test of bivariate normality: Chisquare = 0.5727, df = 2, p = 0.751 Row Thresholds Threshold Std.Err. 1 0.7513 0.04399 Column Thresholds Threshold Std.Err. 1 -0.9572 0.04695 2 0.4829 0.04132 3 1.4930 0.06070 > > > > cleanEx(); ..nameEx <- "polyserial" > > ### * polyserial > > flush(stderr()); flush(stdout()) > > ### Name: polyserial > ### Title: Polyserial Correlation > ### Aliases: polyserial > ### Keywords: models > > ### ** Examples > > data <- rmvnorm(1000, c(0, 0), matrix(c(1, .5, .5, 1), 2, 2)) > x <- data[,1] > y <- data[,2] > cor(x, y) # sample correlation [1] 0.50479 > y <- cut(y, c(-Inf, -1, .5, 1.5, Inf)) > polyserial(x, y) # 2-step estimate [1] 0.484016 > polyserial(x, y, ML=TRUE, std.err=TRUE) # ML estimate Polyserial Correlation, ML est. = 0.4854 (0.02554) Test of bivariate normality: Chisquare = 6.185, df = 11, p = 0.8607 1 2 3 Threshold -0.95390 0.48070 1.48800 Std.Err. 0.04416 0.03809 0.05816 > > > > cleanEx(); ..nameEx <- "print.polycor" > > ### * print.polycor > > flush(stderr()); flush(stdout()) > > ### Name: print.polycor > ### Title: Print Method for polycor Objects > ### Aliases: print.polycor > ### Keywords: print methods > > ### ** Examples > > data <- rmvnorm(1000, c(0, 0), matrix(c(1, .5, .5, 1), 2, 2)) > x <- data[,1] > y <- data[,2] > cor(x, y) # sample correlation [1] 0.50479 > x <- cut(x, c(-Inf, .75, Inf)) > y <- cut(y, c(-Inf, -1, .5, 1.5, Inf)) > polychor(x, y, ML=TRUE, std.err=TRUE) # polychoric correlation, ML estimate Polychoric Correlation, ML est. = 0.4401 (0.04075) Test of bivariate normality: Chisquare = 0.5727, df = 2, p = 0.751 Row Thresholds Threshold Std.Err. 1 0.7513 0.04399 Column Thresholds Threshold Std.Err. 1 -0.9572 0.04695 2 0.4829 0.04132 3 1.4930 0.06070 > > > > ### *