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("labstatR-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('labstatR') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "COV" > > ### * COV > > flush(stderr()); flush(stdout()) > > ### Name: COV > ### Title: Calcola la covarianza non corretta > ### Aliases: COV > ### Keywords: multivariate > > ### ** Examples > > x <- c(1,3,2,4,6,7) > y <- c(7,3,2,1,-1,-3) > cov(x,y) [1] -7.5 > COV(x,y) [1] -6.25 > > > > cleanEx(); ..nameEx <- "E" > > ### * E > > flush(stderr()); flush(stdout()) > > ### Name: E > ### Title: Calcola l'indice di eterogeneita' > ### Aliases: E > ### Keywords: univar > > ### ** Examples > > x <- c("A", "A", "B", "A", "C", "A") > E(x) [1] 0.75 > > > > cleanEx(); ..nameEx <- "Markov" > > ### * Markov > > flush(stderr()); flush(stdout()) > > ### Name: Markov > ### Title: Simulatore di catene di Markov > ### Aliases: Markov Markov2 > ### Keywords: distribution > > ### ** Examples > > x <- c("P","S","N") > P <- matrix(c(0.5,0.5,0.25,0.25,0,0.25,0.25,0.5,0.5),3,3) > Markov("S",15,x,P) -> traj > traj $X [1] "S" "P" "P" "S" "N" "P" "N" "N" "N" "N" "P" "P" "P" "S" "P" "N" $t [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 > plot(traj$t,unclass(factor(traj$X)),type="s",axes=FALSE, + xlab="t",ylab="Che tempo fa'") > axis(1) > axis(2,c(1,2,3),levels(factor(traj$X))) > box() > > > > cleanEx(); ..nameEx <- "Me" > > ### * Me > > flush(stderr()); flush(stdout()) > > ### Name: Me > ### Title: Calcola la mediana anche per fenomeni qualitativi > ### Aliases: Me > ### Keywords: univar > > ### ** Examples > > x <- factor(c("A", "B", "A", "C", "A")) > Me(x) Warning in Me(x) : La mediana non si puo' calcolare!!! [1] NA > > > > cleanEx(); ..nameEx <- "Rp" > > ### * Rp > > flush(stderr()); flush(stdout()) > > ### Name: Rp > ### Title: Calcola l'allocazione ottimale di un portafoglio > ### Aliases: Rp > ### Keywords: distribution > > ### ** Examples > > x <- c(11,9,25,7,-2)/100 > y <- c(-3,15,2,20,6)/100 > pxy <- matrix(rep(0,25),5,5) > pxy[1,1] <- 0.2 > pxy[2,2] <- 0.2 > pxy[3,3] <- 0.2 > pxy[4,4] <- 0.2 > pxy[5,5] <- 0.2 > Rp(x,y,pxy) $a [1] 0.486653 $Rm [1] 0.08973306 $VR [1] 0.00246653 > > > > cleanEx(); ..nameEx <- "Rpa" > > ### * Rpa > > flush(stderr()); flush(stdout()) > > ### Name: Rpa > ### Title: Calcola il rendimento di un portafoglio > ### Aliases: Rpa > ### Keywords: distribution > > ### ** Examples > > x <- c(11,9,25,7,-2)/100 > y <- c(-3,15,2,20,6)/100 > pxy <- matrix(rep(0,25),5,5) > pxy[1,1] <- 0.2 > pxy[2,2] <- 0.2 > pxy[3,3] <- 0.2 > pxy[4,4] <- 0.2 > pxy[5,5] <- 0.2 > Rpa(0.1,x,y,pxy) $Rm [1] 0.082 $VR [1] 0.0053788 > Rpa(0.5,x,y,pxy) $Rm [1] 0.09 $VR [1] 0.00247 > > > > cleanEx(); ..nameEx <- "birthday" > > ### * birthday > > flush(stderr()); flush(stdout()) > > ### Name: birthday > ### Title: Calcola la probabilita' di compleanni coincidenti > ### Aliases: birthday > ### Keywords: distribution > > ### ** Examples > > n <- c(5,10,15,20,21,22,23,24,25,30,50,60, + 70,80,90,100,200,300,365) > for(i in n) + cat("\n n=",i,"P(A)=",birthday(i)) n= 5 P(A)= 0.02713557 n= 10 P(A)= 0.1169482 n= 15 P(A)= 0.2529013 n= 20 P(A)= 0.4114384 n= 21 P(A)= 0.4436883 n= 22 P(A)= 0.4756953 n= 23 P(A)= 0.5072972 n= 24 P(A)= 0.5383443 n= 25 P(A)= 0.5686997 n= 30 P(A)= 0.7063162 n= 50 P(A)= 0.9703736 n= 60 P(A)= 0.9941227 n= 70 P(A)= 0.9991596 n= 80 P(A)= 0.9999143 n= 90 P(A)= 0.9999938 n= 100 P(A)= 0.9999997 n= 200 P(A)= 1 n= 300 P(A)= 1 n= 365 P(A)= 1> > > > cleanEx(); ..nameEx <- "bubbleplot" > > ### * bubbleplot > > flush(stderr()); flush(stdout()) > > ### Name: bubbleplot > ### Title: Disegna un grafico a bolle > ### Aliases: bubbleplot > ### Keywords: multivariate > > ### ** Examples > > x <- c("O","O","S","B","S","O","B","B","S", + "B","O","B","B","O","S") > y <- c("O","B","B","B","S","S","O","O","B", + "B","O","S","B","S","B") > x <- ordered(x, levels=c("S","B","O")) > y <- ordered(y, levels=c("S","B","O")) > table(x,y) y x S B O S 1 3 0 B 1 3 2 O 2 1 2 > bubbleplot(table(x,y),main="Musica versus Pittura") > > > > cleanEx(); ..nameEx <- "chi2" > > ### * chi2 > > flush(stderr()); flush(stdout()) > > ### Name: chi2 > ### Title: Calcola l'indice di connessione > ### Aliases: chi2 > ### Keywords: multivariate > > ### ** Examples > > x <- rbinom(8,5,0.5) > y <- c("A", "A", "B", "A", "B", "B", "C", "B") > chi2(x,y) [1] 0.2777778 > > > > cleanEx(); ..nameEx <- "cv" > > ### * cv > > flush(stderr()); flush(stdout()) > > ### Name: cv > ### Title: Calcola il coefficiente di variazione > ### Aliases: cv > ### Keywords: univar > > ### ** Examples > > x <- c(1,3,2,4,6,7) > cv(x) [1] 0.5516773 > > > > cleanEx(); ..nameEx <- "eta" > > ### * eta > > flush(stderr()); flush(stdout()) > > ### Name: eta > ### Title: Calcola l'indice di dipendenza in media > ### Aliases: eta > ### Keywords: multivariate > > ### ** Examples > > x <- c(rep(1,10),rep(0,23), rep(2,15)) > y <- c(rnorm(10,mean=7),rnorm(23,mean=19),rnorm(15,mean=17)) > eta(x,y) [1] 0.9687662 > y <- c(rnorm(10,mean=8),rnorm(23,mean=7),rnorm(15,mean=6.5)) > eta(x,y) [1] 0.2093498 > > > > cleanEx(); ..nameEx <- "gen.vc" > > ### * gen.vc > > flush(stderr()); flush(stdout()) > > ### Name: gen.vc > ### Title: Simula una variabile casuale discreta > ### Aliases: gen.vc > ### Keywords: distribution > > ### ** Examples > > x <- c(-2,3,7,10,12) > p <- c(0.2, 0.1, 0.4, 0.2, 0.1) > y <- NULL > for(i in 1:1000) y <- c(y,gen.vc(x,p)) > table(y)/length(y) y -2 3 7 10 12 0.200 0.093 0.403 0.194 0.110 > > > > cleanEx(); ..nameEx <- "gini" > > ### * gini > > flush(stderr()); flush(stdout()) > > ### Name: gini > ### Title: Calcola l'indice di concetrazione > ### Aliases: gini > ### Keywords: univar > > ### ** Examples > > x <- c(1,3,4,30,100) > gini(x) $G [1] 0.8152174 $R [1] 0.6521739 $P [1] 0.0 0.2 0.4 0.6 0.8 1.0 $Q [1] 0.000000000 0.007246377 0.028985507 0.057971014 0.275362319 1.000000000 > y <- c(10,10,10,10) > gini(y, add=TRUE,col="red") $G [1] 0 $R [1] 0 $P [1] 0.00 0.25 0.50 0.75 1.00 $Q [1] 0.00 0.25 0.50 0.75 1.00 > > > > cleanEx(); ..nameEx <- "gioco1" > > ### * gioco1 > > flush(stderr()); flush(stdout()) > > ### Name: gioco1 > ### Title: Simula la scommessa di De Mere > ### Aliases: gioco1 gioco1a > ### Keywords: distribution > > ### ** Examples > > ptm <- proc.time() > gioco1a(10000) [1] 0.5195 > proc.time() - ptm [1] 0.19 0.01 0.19 0.00 0.00 > ptm <- proc.time() > gioco1(10000) [1] 0.5196 > proc.time() - ptm [1] 1.00 0.02 1.16 0.00 0.00 > > > > cleanEx(); ..nameEx <- "gioco2" > > ### * gioco2 > > flush(stderr()); flush(stdout()) > > ### Name: gioco2 > ### Title: Simula la scommessa di De Mere > ### Aliases: gioco2 gioco2a > ### Keywords: distribution > > ### ** Examples > > ptm <- proc.time() > gioco2a(10000) [1] 0.4986 > proc.time() - ptm [1] 0.33 0.03 0.36 0.00 0.00 > ptm <- proc.time() > gioco2(10000) [1] 0.4907 > proc.time() - ptm [1] 5.57 0.01 6.12 0.00 0.00 > > > > cleanEx(); ..nameEx <- "hist.pf" > > ### * hist.pf > > flush(stderr()); flush(stdout()) > > ### Name: hist.pf > ### Title: Disegna il poligono di frequenza > ### Aliases: hist.pf > ### Keywords: univar > > ### ** Examples > > x <- rnorm(50) > hist.pf(x,br=5) > > > > cleanEx(); ..nameEx <- "ic.var" > > ### * ic.var > > flush(stderr()); flush(stdout()) > > ### Name: ic.var > ### Title: Calcola intervallo di confidenza per la varianza > ### Aliases: ic.var > ### Keywords: univar > > ### ** Examples > > x <- c(0.39, 0.68, 0.82, 1.35, 1.38, 1.62, 1.70, + 1.71, 1.85, 2.14, 2.89, 3.69) > ic.var(x) [1] 0.4266368 2.4508692 > ic.var(x,FALSE) [1] 0.000000 2.044215 > > > > cleanEx(); ..nameEx <- "interinale" > > ### * interinale > > flush(stderr()); flush(stdout()) > > ### Name: interinale > ### Title: Dati sul lavoro interinale > ### Aliases: interinale > ### Keywords: datasets > > ### ** Examples > > data(interinale) > glm(avviato~., binomial, data=interinale) -> model > model Call: glm(formula = avviato ~ ., family = binomial, data = interinale) Coefficients: (Intercept) sessoM eta esperienzaSI -2.08711 0.10766 -0.03943 0.23706 corsispecSI informaticaSI lingueSI mezzitraspSI 1.63760 0.19965 -0.32134 0.32126 istruzionemedia istruzioneuniv arearesNord-Est arearesNord-Ovest -0.12745 -0.17650 0.46722 0.58942 arearesSud e Isole -1.02883 Degrees of Freedom: 17275 Total (i.e. Null); 17263 Residual Null Deviance: 7528 Residual Deviance: 6937 AIC: 6963 > pr <- predict(model, type="response") > plot(density(pr),xlim=c(0,0.2),main="") > > > > cleanEx(); ..nameEx <- "kurt" > > ### * kurt > > flush(stderr()); flush(stdout()) > > ### Name: kurt > ### Title: Calcola l'indice di curtosi > ### Aliases: kurt > ### Keywords: univar > > ### ** Examples > > x <- rnorm(50) > kurt(x) [1] 3.406608 > y <- rt(50,df=1) > kurt(y) [1] 12.45768 > > > > cleanEx(); ..nameEx <- "lewis" > > ### * lewis > > flush(stderr()); flush(stdout()) > > ### Name: lewis > ### Title: Simulatore di processi di Poisson > ### Aliases: lewis > ### Keywords: distribution > > ### ** Examples > > lewis(20,sin) > > > > cleanEx(); ..nameEx <- "mean.a" > > ### * mean.a > > flush(stderr()); flush(stdout()) > > ### Name: mean.a > ### Title: Calcola la media armonica > ### Aliases: mean.a > ### Keywords: univar > > ### ** Examples > > x <- c(1,3,2,4,6,7) > mean.a(x) [1] 2.507463 > > > > cleanEx(); ..nameEx <- "mean.g" > > ### * mean.g > > flush(stderr()); flush(stdout()) > > ### Name: mean.g > ### Title: Calcola la media geometrica > ### Aliases: mean.g > ### Keywords: univar > > ### ** Examples > > x <- c(1,3,2,4,6,7) > mean.g(x) [1] 3.16648 > > > > cleanEx(); ..nameEx <- "sigma2" > > ### * sigma2 > > flush(stderr()); flush(stdout()) > > ### Name: sigma2 > ### Title: Calcola la varianza non corretta > ### Aliases: sigma2 > ### Keywords: univar > > ### ** Examples > > x <- rnorm(10) > var(x) [1] 0.6093144 > sigma2(x) [1] 0.548383 > > > > cleanEx(); ..nameEx <- "skew" > > ### * skew > > flush(stderr()); flush(stdout()) > > ### Name: skew > ### Title: Calcola l'indice di asimmetria > ### Aliases: skew > ### Keywords: univar > > ### ** Examples > > x <- rnorm(50) > skew(x) [1] -0.6610509 > y <- rchisq(50,df=1) > skew(y) [1] 2.274165 > > > > cleanEx(); ..nameEx <- "test.var" > > ### * test.var > > flush(stderr()); flush(stdout()) > > ### Name: test.var > ### Title: Calcola intervallo di confidenza per la varianza > ### Aliases: test.var > ### Keywords: univar > > ### ** Examples > > x <- rnorm(100, sd=5) > var(x) [1] 20.16905 > test.var(x,20) Ipotesi nulla => H0 : sigma2 = 20 Varianza campionaria: 20.16905 , statistica test: 99.8368Warning in if (alternative == "greater") { : the condition has length > 1 and only the first element will be used p-value: 0.4575253 , livello del test: 0.05 Quantile Chi-quadrato: 123.2252 con 99 gdl Ipotesi alternativa => H1 : sigma2 > 20 Decisione: non si rifuta H0 > > > > cleanEx(); ..nameEx <- "trajectory" > > ### * trajectory > > flush(stderr()); flush(stdout()) > > ### Name: trajectory > ### Title: Simulatore di processi di diffusione > ### Aliases: trajectory > ### Keywords: distribution > > ### ** Examples > > n <- 100 > T <- 1 > x0 <- 1 > mu <- function(x,t) {-x*t} > sigma <- function(x,t) {x*t} > diff <- trajectory(1,0,1,mu,sigma,100) > plot(diff$t,diff$y,type="l") > acf(diff$y, main="Processo di diffusione") > > > > ### *