Laboratorio di ST1 Lezione 4

Similar documents
Package invgamma. May 7, 2017

ST417 Introduction to Bayesian Modelling. Conjugate Modelling (Poisson-Gamma)

Package pearson7. June 22, 2016

Package emg. R topics documented: May 17, 2018

III - MULTIVARIATE RANDOM VARIABLES

Distributions of Functions of Random Variables. 5.1 Functions of One Random Variable

Package Delaporte. August 13, 2017

The Chi-Square and F Distributions

GENERALIZED ERROR DISTRIBUTION

MA20226: STATISTICS 2A 2011/12 Assessed Coursework Sheet One. Set: Lecture 10 12:15-13:05, Thursday 3rd November, 2011 EB1.1

Lecture 5 - Plots and lines

Matematisk statistik allmän kurs, MASA01:A, HT-15 Laborationer

Week 2 Statistics for bioinformatics and escience

Metric Predicted Variable With One Nominal Predictor Variable

cor(dataset$measurement1, dataset$measurement2, method= pearson ) cor.test(datavector1, datavector2, method= pearson )

Package skellam. R topics documented: December 15, Version Date

THE STOCHASTIC INTERPRETATION OF THE DAGUM PERSONAL INCOME DISTRIBUTION: A TALE

Package ForwardSearch

Metric Predicted Variable on One Group

The evdbayes Package

Package qqtest. February 25, 2016

Package LindleyR. June 23, 2016

The normalp Package. October 2, 2007

Package diffeq. February 19, 2015

Explore the data. Anja Bråthen Kristoffersen

Solution to Series 6

Package bpp. December 13, 2016

Examination paper for ST2304 Statistical modelling for biologists and biotechnologists

Statistics for classification

Lecture 22. December 19, Department of Biostatistics Johns Hopkins Bloomberg School of Public Health Johns Hopkins University.

9 Estimating the Underlying Survival Distribution for a

Parametric technique

Handout 4: Simple Linear Regression

Conditional Effects Contrasts of interest main effects" for factor 1: μ i: μ:: i = 1; ; : : : ; a μ i: μ k: i = k main effects" for factor : μ :j μ::

Package gumbel. February 15, 2013

Package sklarsomega. May 24, 2018

R: A Quick Reference

Continuous random variables

Metric Predicted Variable on Two Groups

Properties of Continuous Probability Distributions The graph of a continuous probability distribution is a curve. Probability is represented by area

Sampling Distributions of Statistics Corresponds to Chapter 5 of Tamhane and Dunlop

f Simulation Example: Simulating p-values of Two Sample Variance Test. Name: Example June 26, 2011 Math Treibergs

Stat 502 Design and Analysis of Experiments Normal and Related Distributions (t, χ 2 and F ) Tests, Power, Sample Size & Condence Intervals

Score Test and Likelihood Ratio Test for Zero- Inflated Binomial Distribution and Geometric Distribution

Package depth.plot. December 20, 2015

Explore the data. Anja Bråthen Kristoffersen Biomedical Research Group

Handout 1: Predicting GPA from SAT

CHAPTER 6 : LITERATURE REVIEW

P E R E N C O - C H R I S T M A S P A R T Y

Statistical Computing Session 4: Random Simulation

Inference for Proportions, Variance and Standard Deviation

Package ZIM. R topics documented: August 29, Type Package. Title Statistical Models for Count Time Series with Excess Zeros. Version 1.

1. Definition of a Polynomial

Package RootsExtremaInflections

Examples of fitting various piecewise-continuous functions to data, using basis functions in doing the regressions.

Exercise 5.4 Solution

Customizing pgstar for your models

BEGINNING BAYES IN R. Bayes with discrete models

Transformations of Standard Uniform Distributions

Weldon s dice. Lecture 15 - χ 2 Tests. Labby s dice. Labby s dice (cont.)

Robustness and Distribution Assumptions

1 Probability Distributions

Lesson 14: Model Checking

1 Introduction to Minitab

Package leiv. R topics documented: February 20, Version Type Package

Package normalp. February 20, 2015

Exam 2 Practice Questions, 18.05, Spring 2014

Variable-Specific Entropy Contribution

Biostatistics Xinhai Li Probability distribution

MAS361. MAS361 1 Turn Over SCHOOL OF MATHEMATICS AND STATISTICS. Medical Statistics

February 5, 2018 START HERE. measurement scale. Means. number of means. independent measures t-test Ch dependent measures t-test Ch 16.

At the end, f(m) 0. We can see how this works with a plot using the objective function f(x) = 1/2 e x2 :

Content by Week Week of October 14 27

Economics 205, Fall 2002: Final Examination, Possible Answers

Package bayeslm. R topics documented: June 18, Type Package

The Chi-Square Distributions

Dispersion of a flow that passes a dynamic structure. 5*t 5*t. Time

Stat 704 Data Analysis I Probability Review

MFin Econometrics I Session 5: F-tests for goodness of fit, Non-linearity and Model Transformations, Dummy variables


R STATISTICAL COMPUTING

Univariate Descriptive Statistics for One Sample

Contents 1 Admin 2 General extensions 3 FWL theorem 4 Omitted variable bias 5 The R family Admin 1.1 What you will need Packages Data 1.

χ 2 Test for Frequencies January 15, 2019 Contents

Project One: C Bump functions

Data Skills 08: General Linear Model

STAT 675 Statistical Computing

Lesson 8: Testing for IID Hypothesis with the correlogram

Hypothesis Tests and Confidence Intervals Involving Fitness Landscapes fit by Aster Models By Charles J. Geyer and Ruth G. Shaw Technical Report No.

Online Appendix to Mixed Modeling for Irregularly Sampled and Correlated Functional Data: Speech Science Spplications

Spatial plotting in R

Package decon. February 19, 2015

Meta-analysis for Microarray Experiments

Package goftest. R topics documented: April 3, Type Package

Math 70 Homework 8 Michael Downs. and, given n iid observations, has log-likelihood function: k i n (2) = 1 n

Package sdprisk. December 31, 2016

Continuous Distributions

A Handbook of Statistical Analyses Using R 2nd Edition. Brian S. Everitt and Torsten Hothorn

Single gene analysis of differential expression

Computer Assignment 8 - Discriminant Analysis. 1 Linear Discriminant Analysis

Transcription:

Laboratorio di ST1 Lezione 4 Claudia Abundo Dipartimento di Matematica Università degli Studi Roma Tre 26 Marzo 2010

Gamma?dgamma The Gamma Distribution Description Density, distribution function, quantile function and random generation for the Gamma distribution with parameters shape and scale. Usage dgamma(x, shape, rate = 1, scale = 1/rate, log = FALSE) pgamma(q, shape, rate = 1, scale = 1/rate, lower.tail = TRUE, log.p = FALSE) qgamma(p, shape, rate = 1, scale = 1/rate, lower.tail = TRUE, log.p = FALSE) rgamma(n, shape, rate = 1, scale = 1/rate)

Gamma 2 Arguments x, q vector of quantiles. p vector of probabilities. n number of observations. If length(n) > 1, the length is taken to be the number required. rate an alternative way to specify the scale. shape, scale shape and scale parameters. Must be positive, scale strictly. log, log.p logical; if TRUE, probabilities/densities p are returned as log(p). lower.tail logical; if TRUE (default), probabilities are P[X <= x], otherwise, P[X > x]. Details If scale is omitted, it assumes the default value of 1. The Gamma distribution with parameters shape = a and scale = s has density f(x) = 1/(s a Gamma(a))x ( a 1)e (x/s) forx >= 0, a > 0and s > 0.

Gamma 3 curve(dgamma(x, shape = 0.5, rate = 5), col = "red", ylab = "Densità", from = 0, to = 2, main = "Distribuzione Gamma") curve(dgamma(x, shape = 1, rate = 5), from = 0, to = 2, add = T, lty = 2) curve(dgamma(x, shape = 2, rate = 5), col = "blue", from = 0, to = 2, add = T, lty = 3) curve(dgamma(x, shape = 3, rate = 5), col = "green", from = 0, to = 2, add = T, lty = 4) legend(1.2,6, c("shape = 1/2", "shape = 1", "shape = 2", "shape = 3"), lty = c(1, 2, 3, 4))

Realizzazioni di Gamma s<-c() for (i in 1:10000) s[i]<-mean(rgamma(n=1,1)) hist(s,prob=t,xlim=c(0,4),ylim=c(0,2)) for (i in 1:10000) s[i]<-mean(rgamma(n=5,1)) hist(s,prob=t,xlim=c(0,4),ylim=c(0,2)) for (i in 1:10000) s[i]<-mean(rgamma(n=10,1)) hist(s,prob=t,xlim=c(0,4),ylim=c(0,2)) for (i in 1:10000) s[i]<-mean(rgamma(n=20,1)) hist(s,prob=t,xlim=c(0,4),ylim=c(0,2))

Chi Quadrato Per n > 0, la distribuzione gamma con parametro di forma k = n / 2 e parametro di scala 2 è detta distribuzione chi-square con n gradi di libertà. The (non-central) Chi-Squared Distribution Density, distribution function, quantile function and random generation for the chi-squared distribution with df degrees of freedom and optional non-centrality parameter ncp. dchisq(x, df, ncp=0, log = FALSE) pchisq(q, df, ncp=0, lower.tail = TRUE, log.p = FALSE) qchisq(p, df, ncp=0, lower.tail = TRUE, log.p = FALSE) rchisq(n, df, ncp=0)

Chi Quadrato 2 curve(dchisq(x, df = 3), 0.,20, ylab = "Densità", col = "red", main = "Distribuzione CHI-Quadrato") curve(dchisq(x, df = 5), 0.,20, ylab = "Densità", col = "blue", lty = 2, add = T) curve(dchisq(x, df = 7), 0.,20, ylab = "Densità", col = "green", lty = 2, add = T) legend(10,0.2, c("gdl = 3", "gdl = 5", "gdl = 7"), lty = c(1, 2, 3))

Chi Quadrato 3: 1 g.d.l. Se Z ha distribuzione normale standard, Z 2 ha una distribuzione chi-quadrato con 1 grado di libertà. curve(dchisq(x, df = 1), 0.,20, ylab = "Densit a",col = + "red", main = "Distribuzione CHI-Quadrato") qchisq(0.95, df=1) points(qchisq(0.95, df=1), 0, pch=" ") gli ultimi due comandi calcolano e individuano sul grafico il quantile 0.95. Il quantile 0.95 è 3.84. Notare che la radice quadrata di 3.84 è 1.96: P (Z 2 3.84) = 0.95 P ( Z 1.96) = 0.95 Cioè la probabilità che il chi-quadrato con 1 g.l. sia minore di 3.84 è uguale alla probabilità che la normale standard sia compresa tra -1.96 e 1.96.

t di Student Date la v.a. Z standardizzata e la v.a. X chi quadro con n g.d.l la v.a. T = una t con n g.d.l. Z (X/n) 1 /2 è curve(dnorm(x), -5, 5, ylab = "Densità", col = "red", main = "Distribuzione t di Student") curve(dt(x, df = 1), -6, 6, lty = 2, col = "blue", add = T) curve(dt(x, df = 2), -6, 6, lty = 3, col = "green", add = T) legend(2,0.3, c("z", "t, gdl = 1", "t, gdl = 2"), lty = c(1, 2, 3)) df = degrees of freedom

F di Fisher Date due v.a. chi quadro con rispettivamente n e m g.d.l. la v.a. F = χ2 n /n χ 2 è una F di m /m Fisher con n e m g.d.l. Density, distribution function, quantile function and random generation for the F distribution with df1 and df2 degrees of freedom (and optional non-centrality parameter ncp). df(x, df1, df2, ncp, log = FALSE) pf(q, df1, df2, ncp, lower.tail = TRUE, log.p = FALSE) qf(p, df1, df2, ncp, lower.tail = TRUE, log.p = FALSE) rf(n, df1, df2, ncp) x, q vector of quantiles. p vector of probabilities. n number of observations. If length(n) > 1, the length is taken to be the number required. df1, df2 degrees of freedom. Inf is allowed. ncp non-centrality parameter. If omitted the central F is assumed. log, log.p logical; if TRUE, probabilities p are given as log(p). lower.tail logical; if TRUE (default), probabilities are P [X <= x], otherwise, P [X > x].

F di Fisher 2 curve(df(x, df1 =3, df2 = 2), 0, 2, ylab = "Densità", col = "red", main = "Distribuzione f di Fisher") curve(df(x, df1 =4, df2 = 3), 0, 2, ylab = "Densità", col = "blue", add = T)

Beta curve(dbeta(x,5,3), ylim=c(0,3), xlim=c(0,1), ylab="densità Beta")

Cambio di parametri Beta 2 curve(dbeta(x,1,1), ylim=c(0,3), xlim=c(0,1), ylab="densità Beta") curve(dbeta(x,0.1,1), add = TRUE, lty = 3, col = "red") curve(dbeta(x,1,0.1), add = TRUE, lty = 3, col = "red") curve(dbeta(x,0.1,0.1), add = TRUE, lty = 2, lwd = 2, col = "green") curve(dbeta(x,4,4), add = TRUE, lty = 2, lwd = 2) curve(dbeta(x,2,6), add = TRUE, lty = 2, lwd = 3, col = "blue") curve(dbeta(x,6,2), add = TRUE, lty = 2, lwd = 3, col = "blue") curve(dbeta(x,2,6), add = TRUE, lty = 2, lwd = 3, col = "blue") curve(dbeta(x,2,2), add = TRUE, lty = 2, lwd = 3)

Below, we will show how to export a graph into a JPEG image file. The main trick is to call the function jpeg(). It has only one required argument, which is the filepath to the JPEG file. Once the function jpeg() has been called, all subsequent graphing will be done inside of the specified JPEG file. Therefore, the following code will create a line graph in a file named test.jpg. (The file will be saved in the directory where R was originally run.) > data <- read.table("data/dow-jones.csv", header=true) # read data > jpeg("test.jpg") # graph to JPEG file > plot(data$year, data$start, type="line", # create graph + xlab="year", ylab="djia", main="dow Jones Industrial Average") # label axes and add title > dev.off() # close file > q() Before quitting R, it is important to close the file with the command dev.off() to ensure that R does not continue to write to it in future sessions.