differenzaresa = c(106, -20, 101, -33, 72, -36, 62, 38, -70, 127, 24) mean(differenzaresa) t.test(differenzaresa)$estimate t.test(differenzaresa)$null.value (mean(differenzaresa) - 0) /(sd(differenzaresa)/sqrt(11)) t.test(differenzaresa)$statistic par(mfrow = c(1,2)) x = seq(from = -2.5, to = 2.5, by = .01) y = dnorm(x) plot(x, y, "l", ylim = c(0, 0.4), main = "distribuzione normale", lty = 2) tright = seq(1.690476, 3, by = 0.01) yright = dnorm(tright) xx = c(1.690476, tright, 3, 3, 1.690476 ) yy = c(0, yright, dnorm(3),0, 0) polygon(xx, yy, col = "violet", density = 20, angle = -60) points(1.690476, 0, pch =19) text(1.6, 0, "1.69", 1) tleft = seq( -3, -1.690476, by = 0.01) yleft = dnorm(tleft) xx = c(-3, tleft, -1.690476, -1.690476, -3 ) yy = c(0, yleft, dnorm(-1.690476),0, 0) polygon(xx, yy, col = "violet", density = 20, angle = -60) points(-1.690476, 0, pch =19) text(-1.4, 0, "-1.69") x = seq(from = -2.5, to = 2.5, by = .01) y = dnorm(x) plot(x, y, "l", ylim = c(0, 0.4), main = "distribuzione t di Student", lty = 2) yt = dt(x, df = 10) lines(x, yt, lwd = 2, col = "orange") tright = seq(1.690476, 3, by = 0.01) yright = dt(tright, df = 10) xx = c(1.690476, tright, 3, 3, 1.690476 ) yy = c(0, yright, dt(3, df = 10),0, 0) polygon(xx, yy, col = "orange", density = 20, angle = -30) points(1.690476, 0, pch =19) text(1.6, 0, "1.69", 1) tleft = seq( -3, -1.690476, by = 0.01) yleft = dt(tleft, df = 10) xx = c(-3, tleft, -1.690476, -1.690476, -3 ) yy = c(0, yleft, dt(-1.690476, df = 10),0, 0) polygon(xx, yy, col = "orange", density = 20, angle = -30) points(-1.690476, 0, pch =19) text(-1.4, 0, "-1.69") 2 * (1 - pnorm(1.690476)) ## 0.09 length(differenzaresa) - length(mean(differenzaresa)) t.test(differenzaresa)$parameter 2 * (1 - pt(q = 1.690476, df = 10)) t.test(differenzaresa)$p.value ## raul = read.csv(file.choose(), header = TRUE) www = "http://www.biostatisticaumg.it/dataset/raul.csv" raul = read.csv(www, header = TRUE) attach(raul) names(raul) table(Esito) 2018/2 1278/2 verde = split(Ca125, Esito)[[1]] rosso = split(Ca125, Esito)[[2]] t.test(verde, rosso) ###t.test(Ca125[Esito == "benigno"], Ca125[Esito == "maligno"], var.equal = TRUE) t.test(Ca125[Esito == "benigno"], Ca125[Esito == "maligno"]) t.test(Ca125 ~ Esito) verde = split(Ca125, Esito)[[1]] rosso = split(Ca125, Esito)[[2]] boxplot(verde, rosso, col = c("green", "red"), horizontal = TRUE) summary(verde) summary(rosso) boxplot(verde, rosso, col = c("green", "red"), horizontal = TRUE) quantile(rosso, .2) quantile(verde, .9) sum(rosso < 28) sum(rosso < 16) sort(rosso) sum(rosso > 100) cov(Ldhuno, Ldhtre) cor(Ldhuno, Ldhtre) attach(airquality) cor(Temp, Ozone) cor(Temp, Ozone, use = "complete.obs") lm(Ldhtre ~ Ldhuno) -0.223 * sd(Ldhuno) / sd(Ldhtre) cor(Ldhuno, Ldhtre) summary(lm(Ldhtre ~ Ldhuno)) summary(lm(Ldhtre ~ Ldhuno * Esito))