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("smoothSurv-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('smoothSurv') Loading required package: survival Loading required package: splines > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "a.to.c" > > ### * a.to.c > > flush(stderr()); flush(stdout()) > > ### Name: a.to.c > ### Title: Work Function for 'smoothSurvReg' > ### Aliases: a.to.c > ### Keywords: internal utilities > > ### ** Examples > > ccoef <- c(0.1, 0.2, 0.15, 0.3, 0.25) > > ### Compute 'a' counterparts > acoef <- c.to.a(ccoef, 1) > print(acoef) [1] 0.0000000 0.6931472 0.4054651 1.0986123 0.9162907 > > ### And back 'c', ccoef2 should be same as ccoef > ccoef2 <- a.to.c(acoef) > print(ccoef2) [1] 0.10 0.20 0.15 0.30 0.25 > > > > cleanEx(); ..nameEx <- "c.to.a" > > ### * c.to.a > > flush(stderr()); flush(stdout()) > > ### Name: c.to.a > ### Title: Work Function for 'smoothSurvReg' > ### Aliases: c.to.a > ### Keywords: internal utilities > > ### ** Examples > > ccoef <- c(0.1, 0.2, 0.15, 0.3, 0.25) > > ### Compute 'a' counterparts > acoef <- c.to.a(ccoef, 1) > print(acoef) [1] 0.0000000 0.6931472 0.4054651 1.0986123 0.9162907 > > ### And back 'c', ccoef2 should be same as ccoef > ccoef2 <- a.to.c(acoef) > print(ccoef2) [1] 0.10 0.20 0.15 0.30 0.25 > > > > cleanEx(); ..nameEx <- "dextreme" > > ### * dextreme > > flush(stderr()); flush(stdout()) > > ### Name: extreme value > ### Title: Density of the Extreme Value Distribution of a Minimum. > ### Aliases: dextreme dstextreme > ### Keywords: distribution > > ### ** Examples > > dextreme(1, (sqrt(6)/pi)*0.5772, sqrt(6)/pi) [1] 0.3428868 > dstextreme(1) ## approximately same result as on the previous row [1] 0.3428868 > > > > cleanEx(); ..nameEx <- "dstlogis" > > ### * dstlogis > > flush(stderr()); flush(stdout()) > > ### Name: standardized logistic > ### Title: Density of Standardized Logistic Distribution. > ### Aliases: dstlogis > ### Keywords: distribution > > ### ** Examples > > dstlogis(0) [1] 0.4534498 > dstlogis(seq(-3, 3, 0.2)) [1] 0.007792275 0.011157620 0.015950279 0.022748323 0.032335707 0.045746471 [7] 0.064286993 0.089495749 0.122969777 0.165956721 0.218615885 0.278965591 [13] 0.341842078 0.398647963 0.438853129 0.453449841 0.438853129 0.398647963 [19] 0.341842078 0.278965591 0.218615885 0.165956721 0.122969777 0.089495749 [25] 0.064286993 0.045746471 0.032335707 0.022748323 0.015950279 0.011157620 [31] 0.007792275 > > > > cleanEx(); ..nameEx <- "eval.Gspline" > > ### * eval.Gspline > > flush(stderr()); flush(stdout()) > > ### Name: eval.Gspline > ### Title: Evaluate a G-spline in a grid of values > ### Aliases: eval.Gspline > ### Keywords: dplot > > ### ** Examples > > spline <- minPenalty(knots=seq(-4.2, 4.2, by=0.3), sdspline=0.2, difforder=3)$spline Iter.: 0, Penalty = -0.0259989, Mean constr. = -2.63013e-17, Var constr.= 8.88178e-16 Iter.: 1, Penalty = -0.00650044, Mean constr. = 1.68912e-16, Var constr.= -5.51703e-06 Iter.: 2, Penalty = -0.00162564, Mean constr. = -2.53666e-17, Var constr.= -1.54151e-06 Iter.: 3, Penalty = -5.61756e-12, Mean constr. = -4.52449e-15, Var constr.= 2.59723e-06 Iter.: 4, Penalty = 4.07663e-14, Mean constr. = 1.96402e-17, Var constr.= 1.0404e-10 Iter.: 5, Penalty = 6.12424e-14, Mean constr. = -2.08348e-17, Var constr.= 1.03837e-10 Iter.: 6, Penalty = -3.76587e-16, Mean constr. = -4.40899e-17, Var constr.= 1.03634e-10 Iter.: 7, Penalty = 3.52339e-14, Mean constr. = 2.34972e-17, Var constr.= 9.07681e-11 Convergence reached. > values <- eval.Gspline(spline, seq(-4.5, 4.5, by=0.05)) > plot(values, type="l", bty="n", lwd=3) > > > > cleanEx(); ..nameEx <- "find.c" > > ### * find.c > > flush(stderr()); flush(stdout()) > > ### Name: find.c > ### Title: Work Function for 'smoothSurvReg' > ### Aliases: find.c > ### Keywords: internal utilities > > ### ** Examples > > knots <- seq(-4, 4, 0.5) > sd0 <- 0.3 > ccoef <- find.c(knots, sd0, dist = "dstlogis") > > ### We plot the approximation together with the truth > ### > grid <- seq(-4, 4, 0.05) > truth <- dstlogis(grid) > > ### Following lines compute the values of the approximation > grid.big <- matrix(grid, nrow = length(grid), ncol = length(knots)) > knots.big <- matrix(knots, nrow = length(grid), ncol = length(knots), byrow = TRUE) > normals <- dnorm(grid.big, mean = knots.big, sd = sd0) > approx <- normals %*% ccoef > > ### Plot it > plot(grid, approx, type = "l", xlab = "y", ylab = "f(y)", bty = "n") > lines(grid, truth, lty = 2) > legend(-4, 0.35, c("approx", "truth"), lty = 1:2, bty = "n") > > > > cleanEx(); ..nameEx <- "give.c" > > ### * give.c > > flush(stderr()); flush(stdout()) > > ### Name: give.c > ### Title: Work Function for 'smoothSurvReg' > ### Aliases: give.c > ### Keywords: internal utilities > > ### ** Examples > > knots <- seq(-4, 4, 0.5) > sd0 <- 0.3 > ccoef <- find.c(knots, sd0, dist = "dstlogis") > > last.three <- c(3, 7, 10) > c.rest <- ccoef[-last.three] > ccoef2 <- give.c(knots, sd0, last.three, c.rest) > > print(ccoef) [1] 0.0006121787 0.0013515103 0.0033765642 0.0082849182 0.0201061210 [6] 0.0473784957 0.1037605134 0.1916892655 0.2445901615 0.1916892655 [11] 0.1037605134 0.0473784957 0.0201061210 0.0082849182 0.0033765642 [16] 0.0013515103 0.0006121787 > print(ccoef2) ## Almost no change [1] 0.0006121787 0.0013515103 0.0054330551 0.0082849182 0.0201061210 [6] 0.0473784957 0.0997256028 0.1916892655 0.2445901615 0.1959583899 [11] 0.1037605134 0.0473784957 0.0201061210 0.0082849182 0.0033765642 [16] 0.0013515103 0.0006121787 > > > > cleanEx(); ..nameEx <- "minPenalty" > > ### * minPenalty > > flush(stderr()); flush(stdout()) > > ### Name: minPenalty > ### Title: Minimize the penalty term under the two (mean and variance) > ### constraints > ### Aliases: minPenalty > ### Keywords: optimize > > ### ** Examples > > optimum <- minPenalty(knots=seq(-4.2, 4.2, by = 0.3), sdspline=0.2, difforder=3) Iter.: 0, Penalty = -0.0259989, Mean constr. = -2.63013e-17, Var constr.= 8.88178e-16 Iter.: 1, Penalty = -0.00650044, Mean constr. = 1.68912e-16, Var constr.= -5.51703e-06 Iter.: 2, Penalty = -0.00162564, Mean constr. = -2.53666e-17, Var constr.= -1.54151e-06 Iter.: 3, Penalty = -5.61756e-12, Mean constr. = -4.52449e-15, Var constr.= 2.59723e-06 Iter.: 4, Penalty = 4.07663e-14, Mean constr. = 1.96402e-17, Var constr.= 1.0404e-10 Iter.: 5, Penalty = 6.12424e-14, Mean constr. = -2.08348e-17, Var constr.= 1.03837e-10 Iter.: 6, Penalty = -3.76587e-16, Mean constr. = -4.40899e-17, Var constr.= 1.03634e-10 Iter.: 7, Penalty = 3.52339e-14, Mean constr. = 2.34972e-17, Var constr.= 9.07681e-11 Convergence reached. > where <- optimum$spline > print(where) Knot SD basis c coef. a coef. knot[1] -4.2 0.2 1.251632e-05 -9.18589776 knot[2] -3.9 0.2 4.436442e-05 -7.92049348 knot[3] -3.6 0.2 1.431808e-04 -6.74882285 knot[4] -3.3 0.2 4.207528e-04 -5.67088586 knot[5] -3.0 0.2 1.125800e-03 -4.68668253 knot[6] -2.7 0.2 2.742756e-03 -3.79621285 knot[7] -2.4 0.2 6.084224e-03 -2.99947682 knot[8] -2.1 0.2 1.228896e-02 -2.29647444 knot[9] -1.8 0.2 2.260046e-02 -1.68720571 knot[10] -1.5 0.2 3.784525e-02 -1.17167063 knot[11] -1.2 0.2 5.770287e-02 -0.74986921 knot[12] -0.9 0.2 8.010791e-02 -0.42180143 knot[13] -0.6 0.2 1.012618e-01 -0.18746730 knot[14] -0.3 0.2 1.165487e-01 -0.04686683 knot[15] 0.0 0.2 1.221410e-01 0.00000000 knot[16] 0.3 0.2 1.165487e-01 -0.04686683 knot[17] 0.6 0.2 1.012618e-01 -0.18746730 knot[18] 0.9 0.2 8.010791e-02 -0.42180143 knot[19] 1.2 0.2 5.770287e-02 -0.74986921 knot[20] 1.5 0.2 3.784525e-02 -1.17167063 knot[21] 1.8 0.2 2.260046e-02 -1.68720571 knot[22] 2.1 0.2 1.228896e-02 -2.29647444 knot[23] 2.4 0.2 6.084224e-03 -2.99947682 knot[24] 2.7 0.2 2.742756e-03 -3.79621285 knot[25] 3.0 0.2 1.125800e-03 -4.68668253 knot[26] 3.3 0.2 4.207528e-04 -5.67088586 knot[27] 3.6 0.2 1.431808e-04 -6.74882285 knot[28] 3.9 0.2 4.436442e-05 -7.92049348 knot[29] 4.2 0.2 1.251632e-05 -9.18589776 > show <- eval.Gspline(where, seq(-4.2, 4.2, by=0.05)) > plot(show, type="l", bty="n", lwd=2) > > > > cleanEx(); ..nameEx <- "piece" > > ### * piece > > flush(stderr()); flush(stdout()) > > ### Name: piece > ### Title: Left Continuous Piecewise Constant Function with a Finite > ### Support. > ### Aliases: piece > ### Keywords: utilities > > ### ** Examples > > my.breaks <- c(-2, 1.5, 4, 7) > my.values <- c(0.5, 0.9, -2) > grid <- seq(-3, 8, by = 0.25) > piece(grid, my.breaks, my.values) [1] 0.0 0.0 0.0 0.0 0.0 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 [16] 0.5 0.5 0.5 0.5 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 -2.0 [31] -2.0 -2.0 -2.0 -2.0 -2.0 -2.0 -2.0 -2.0 -2.0 -2.0 -2.0 0.0 0.0 0.0 0.0 > > > > cleanEx(); ..nameEx <- "smoothSurvReg" > > ### * smoothSurvReg > > flush(stderr()); flush(stdout()) > > ### Name: smoothSurvReg > ### Title: Regression for a Survival Model with Smoothed Error Distribution > ### Aliases: smoothSurvReg > ### Keywords: survival smooth > > ### ** Examples > > ### We generate interval censored data and fit a model with few artificial covariates > x1 <- rbinom(50, 1, 0.4) ## binary covariate > x2 <- rnorm(50, 180, 10) ## continuous covariate > y1 <- 0.5*x1 - 0.01*x2 + 0.005 *x1*x2 + 1.5*rnorm(50, 0, 1) ## generate log(T), left limit > t1 <- exp(y1) ## left limit of the survival time > t2 <- t1 + rgamma(50, 1, 1) ## right limit of the survival time > surv <- Surv(t1, t2, type = "interval2") ## survival object > > ## Fit the model with an interaction > fit1 <- smoothSurvReg(surv ~ x1 * x2, logscale = ~1, info = FALSE, lambda = exp(2:(-1))) Fit with Log(Lambda) = 2, AIC(7.389056) = -88.61158, df(7.389056) = 5.946675, 5 iterations, fail = 0 Fit with Log(Lambda) = 1, AIC(2.718282) = NA, df(2.718282) = NA, NA iterations, fail = 103 Fit with Log(Lambda) = 0, AIC(1) = -87.31, df(1) = 6.65778, 14 iterations, fail = 0 Fit with Log(Lambda) = -1, AIC(0.3678794) = -86.80626, df(0.3678794) = 6.991268, 16 iterations, fail = 0 > > ## Print the summary information > summary(fit1, spline = TRUE) Call: smoothSurvReg(formula = surv ~ x1 * x2, logscale = ~1, lambda = exp(2:(-1)), info = FALSE) Estimated Regression Coefficients: Value Std.Error Std.Error2 Z Z2 p p2 (Intercept) 1.24499 4.19250 3.25489 0.2970 0.3825 0.7665 0.70209 x1 5.23252 5.05405 4.10865 1.0353 1.2735 0.3005 0.20283 x2 -0.01060 0.02276 0.01758 -0.4656 -0.6026 0.6415 0.54677 x1:x2 -0.02557 0.02722 0.02257 -0.9391 -1.1328 0.3477 0.25729 Log(scale) -0.14146 0.10245 0.08511 -1.3809 -1.6622 0.1673 0.09647 Scale = 0.8681 Details on (Fitted) Error Distribution: Knot SD basis c coef. Std.Error.c Std.Error2.c Z Z2 knot[1] -6.0 0.2 1.160e-30 7.296e-29 3.170e-29 0.01590 0.03660 knot[2] -5.7 0.2 1.674e-27 9.059e-26 4.059e-26 0.01848 0.04124 knot[3] -5.4 0.2 1.591e-24 7.335e-23 3.397e-23 0.02169 0.04683 knot[4] -5.1 0.2 9.952e-22 3.868e-20 1.856e-20 0.02573 0.05363 knot[5] -4.8 0.2 4.099e-19 1.327e-17 6.610e-18 0.03090 0.06202 knot[6] -4.5 0.2 1.112e-16 2.953e-15 1.533e-15 0.03765 0.07254 knot[7] -4.2 0.2 1.985e-14 4.256e-13 2.309e-13 0.04665 0.08599 knot[8] -3.9 0.2 2.334e-12 3.959e-11 2.254e-11 0.05896 0.10354 knot[9] -3.6 0.2 1.807e-10 2.368e-09 1.422e-09 0.07631 0.12707 knot[10] -3.3 0.2 9.210e-09 9.057e-08 5.770e-08 0.10169 0.15963 knot[11] -3.0 0.2 3.091e-07 2.200e-06 1.497e-06 0.14051 0.20650 knot[12] -2.7 0.2 6.830e-06 3.359e-05 2.461e-05 0.20336 0.27756 knot[13] -2.4 0.2 9.936e-05 3.177e-04 2.528e-04 0.31276 0.39303 knot[14] -2.1 0.2 9.518e-04 1.823e-03 1.585e-03 0.52208 0.60041 knot[15] -1.8 0.2 6.003e-03 6.166e-03 5.778e-03 0.97357 1.03896 knot[16] -1.5 0.2 2.494e-02 1.214e-02 1.061e-02 2.05409 2.35137 knot[17] -1.2 0.2 6.846e-02 1.669e-02 NaN 4.10171 NaN knot[18] -0.9 0.2 1.262e-01 2.278e-02 9.521e-03 5.54110 13.25504 knot[19] -0.6 0.2 1.611e-01 3.020e-02 2.497e-02 5.33412 6.45070 knot[20] -0.3 0.2 1.510e-01 3.458e-02 NaN 4.36627 NaN knot[21] 0.0 0.2 1.147e-01 2.779e-02 NaN 4.12634 NaN knot[22] 0.3 0.2 7.966e-02 1.817e-02 5.694e-03 4.38334 13.98965 knot[23] 0.6 0.2 5.669e-02 1.495e-02 1.109e-02 3.79252 5.11156 knot[24] 0.9 0.2 4.464e-02 1.692e-02 5.439e-03 2.63771 8.20758 knot[25] 1.2 0.2 3.971e-02 1.941e-02 NaN 2.04611 NaN knot[26] 1.5 0.2 3.802e-02 1.895e-02 NaN 2.00660 NaN knot[27] 1.8 0.2 3.511e-02 1.280e-02 NaN 2.74386 NaN knot[28] 2.1 0.2 2.726e-02 6.962e-03 3.959e-03 3.91611 6.88741 knot[29] 2.4 0.2 1.607e-02 9.250e-03 NaN 1.73682 NaN knot[30] 2.7 0.2 6.833e-03 7.627e-03 NaN 0.89590 NaN knot[31] 3.0 0.2 2.066e-03 3.799e-03 1.341e-03 0.54380 1.54098 knot[32] 3.3 0.2 4.429e-04 1.249e-03 6.639e-04 0.35471 0.66702 knot[33] 3.6 0.2 6.727e-05 2.785e-04 1.678e-04 0.24155 0.40083 knot[34] 3.9 0.2 7.239e-06 4.250e-05 2.649e-05 0.17034 0.27332 knot[35] 4.2 0.2 5.521e-07 4.453e-06 2.757e-06 0.12397 0.20026 knot[36] 4.5 0.2 2.983e-08 3.214e-07 1.939e-07 0.09282 0.15386 knot[37] 4.8 0.2 1.142e-09 1.603e-08 9.339e-09 0.07127 0.12231 knot[38] 5.1 0.2 3.099e-11 5.539e-10 3.106e-10 0.05595 0.09977 knot[39] 5.4 0.2 5.957e-13 1.330e-11 7.172e-12 0.04477 0.08306 knot[40] 5.7 0.2 8.114e-15 2.227e-13 1.154e-13 0.03644 0.07029 knot[41] 6.0 0.2 7.831e-17 2.603e-15 1.298e-15 0.03009 0.06031 p p2 knot[1] 9.873e-01 9.708e-01 knot[2] 9.853e-01 9.671e-01 knot[3] 9.827e-01 9.627e-01 knot[4] 9.795e-01 9.572e-01 knot[5] 9.753e-01 9.505e-01 knot[6] 9.700e-01 9.422e-01 knot[7] 9.628e-01 9.315e-01 knot[8] 9.530e-01 9.175e-01 knot[9] 9.392e-01 8.989e-01 knot[10] 9.190e-01 8.732e-01 knot[11] 8.883e-01 8.364e-01 knot[12] 8.389e-01 7.813e-01 knot[13] 7.545e-01 6.943e-01 knot[14] 6.016e-01 5.482e-01 knot[15] 3.303e-01 2.988e-01 knot[16] 3.997e-02 1.870e-02 knot[17] 4.101e-05 NaN knot[18] 3.006e-08 4.219e-40 knot[19] 9.601e-08 1.113e-10 knot[20] 1.264e-05 NaN knot[21] 3.686e-05 NaN knot[22] 1.169e-05 1.803e-44 knot[23] 1.491e-04 3.195e-07 knot[24] 8.347e-03 2.257e-16 knot[25] 4.075e-02 NaN knot[26] 4.479e-02 NaN knot[27] 6.072e-03 NaN knot[28] 8.999e-05 5.682e-12 knot[29] 8.242e-02 NaN knot[30] 3.703e-01 NaN knot[31] 5.866e-01 1.233e-01 knot[32] 7.228e-01 5.048e-01 knot[33] 8.091e-01 6.885e-01 knot[34] 8.647e-01 7.846e-01 knot[35] 9.013e-01 8.413e-01 knot[36] 9.260e-01 8.777e-01 knot[37] 9.432e-01 9.027e-01 knot[38] 9.554e-01 9.205e-01 knot[39] 9.643e-01 9.338e-01 knot[40] 9.709e-01 9.440e-01 knot[41] 9.760e-01 9.519e-01 Penalized Loglikelihood and Its Components: Log-likelihood: -79.81499 Penalty: -0.8711076 Penalized Log-likelihood: -80.6861 Degree of smoothing: Number of parameters: 43 Mean parameters: 4 Scale parameters: 1 Spline parameters: 38 Lambda: 0.3678794 Log(Lambda): -1 df: 6.991268 AIC (higher is better): -86.80626 Number of Newton-Raphson Iterations: 16 n = 50 > > ## Plot the fitted error distribution > plot(fit1) > > ## Plot the fitted error distribution with its components > plot(fit1, components = TRUE) > > ## Plot the cumulative distribution function corresponding to the error density > survfit(fit1, cdf = TRUE) > > ## Plot survivor curves for persons with (x1, x2) = (0, 180) and (1, 180) > cov <- matrix(c(0, 180, 0, 1, 180, 180), ncol = 3, byrow = TRUE) > survfit(fit1, cov = cov) > > ## Plot hazard curves for persons with (x1, x2) = (0, 180) and (1, 180) > cov <- matrix(c(0, 180, 0, 1, 180, 180), ncol = 3, byrow = TRUE) > hazard(fit1, cov = cov) > > ## Plot densities for persons with (x1, x2) = (0, 180) and (1, 180) > cov <- matrix(c(0, 180, 0, 1, 180, 180), ncol = 3, byrow = TRUE) > fdensity(fit1, cov = cov) > > ## Compute estimates expectations of survival times for persons with > ## (x1, x2) = (0, 180), (1, 180), (0, 190), (1, 190), (0, 200), (1, 200) > ## and estimates of a difference of these expectations: > ## T(0, 180) - T(1, 180), T(0, 190) - T(1, 190), T(0, 200) - T(1, 200), > cov1 <- matrix(c(0, 180, 0, 0, 190, 0, 0, 200, 0), ncol = 3, byrow = TRUE) > cov2 <- matrix(c(1, 180, 180, 1, 190, 190, 1, 200, 200), ncol = 3, byrow = TRUE) > print(estimTdiff(fit1, cov1 = cov1, cov2 = cov2)) Covariate Values Compared: Covariate values for T1: x1 x2 x1:x2 Value 1 0 180 0 Value 2 0 190 0 Value 3 0 200 0 Covariate values for T2: x1 x2 x1:x2 Value 1 1 180 180 Value 2 1 190 190 Value 3 1 200 200 Estimates of Expectations: T1 Std.Error Z p Value 1 0.8059 1.320 0.6107 0.5414 Value 2 0.7248 1.184 0.6123 0.5403 Value 3 0.6520 1.082 0.6023 0.5470 T2 Std.Error Z p Value 1 1.5138 2.499 0.6058 0.5446 Value 2 1.0545 1.751 0.6021 0.5471 Value 3 0.7345 1.236 0.5944 0.5522 T1 - T2 Std.Error Z p Value 1 -0.70800 1.2249 -0.5780 0.5633 Value 2 -0.32962 0.6211 -0.5307 0.5956 Value 3 -0.08251 0.3629 -0.2274 0.8201 > > ## More involved examples can be found in script files > ## used to perform analyses and draw pictures > ## presented in /doc/paper1.pdf and /doc/paper2.pdf of this library. > ## These scripts can be found as *.tar.gz files in the same directory. > ## > ## I am not sure whether Windows precombiled binary distributions > ## of contributed packages contain this directory. > ## If not, download source version of the library from CRAN > ## (tar.gz file), unpack it and you find it. > > > > > cleanEx(); ..nameEx <- "std.data" > > ### * std.data > > flush(stderr()); flush(stdout()) > > ### Name: std.data > ### Title: Standardization of the Data > ### Aliases: std.data > ### Keywords: manip > > ### ** Examples > > variable1 <- rnorm(30) > variable2 <- rbinom(30, 1, 0.4) > variable3 <- runif(30) > data.example <- data.frame(variable1, variable2, variable3) > ## We standardize only the first and the third column. > data.std <- std.data(data.example, c("variable1", "variable3")) Number of standardized columns: 2 Used means and sd's: variable1 variable3 mean 0.08245817 0.5161663 sd 0.92412083 0.2853755 > print(data.std) variable1 variable2 variable3 1 -0.767120446 1 -0.9690280 2 0.109493425 0 -1.6022114 3 -0.993470503 0 0.4419510 4 1.637039863 0 1.2618565 5 0.267334741 1 0.9207111 6 -0.977065475 0 0.9851671 7 0.438222871 0 -0.2133744 8 0.709719461 1 -0.3717284 9 0.533829741 0 1.0326884 10 -0.419692475 1 0.3110534 11 1.546684110 0 0.4855275 12 0.332624325 1 -0.5710686 13 -0.761479160 0 -0.8616931 14 -2.485776741 0 1.6697921 15 1.128069748 0 0.4111320 16 -0.137851865 1 -1.0616122 17 -0.106748415 1 -1.3553858 18 0.932105430 0 -0.1333269 19 0.799422547 1 1.4293735 20 0.553437533 1 0.2894246 21 0.905205442 0 1.6119267 22 0.757128408 1 0.7555877 23 -0.008541293 0 -0.5587002 24 -2.241925304 0 -0.2967759 25 0.581490604 1 -1.2893703 26 -0.149966223 0 -1.7629007 27 -0.257816586 1 0.6987278 28 -1.680744021 0 -1.4471530 29 -0.606639531 0 -0.2448771 30 0.363029790 0 0.4342866 > print(c(mean(data.std$variable1), sd(data.std$variable1))) [1] -9.251859e-18 1.000000e+00 > print(c(mean(data.std$variable3), sd(data.std$variable3))) [1] -9.621933e-17 1.000000e+00 > > > > ### *