0% found this document useful (0 votes)
6 views9 pages

Donnees Mathematique

Uploaded by

allechikrisivane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views9 pages

Donnees Mathematique

Uploaded by

allechikrisivane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1) frequency distribution

x=scan()
> breaks=seq(from=1,to=21,by=4)
> breaks
[1] 1 5 9 13 17 21
> classes=cut(x,breaks,right=F)
> frequency=table(classes)
> n=length(x)
> relative.freq=frequency/n
> cumul.freq=cumsum(frequency)
> cumul.rel.freq=cumsum(relative.freq)
> cbind(frequency,relative.freq,cumul.freq,cumul.rel.freq)

2) Ogive plot
x=scan()
> breaks=seq(1,21,4)
> class=cut(x,breaks,right=F)
> frequency=table(class)
> cumul.freq=cumsum(frequency)
> cumul.rel.freq=cumul.freq/length(x)
> xx=breaks-0.5
> yy=c(0,cumul.rel.freq)
> plot(xx,yy,pch=19,col="darkgreen",main="OGIVE PLOT")
> lines(xx,yy,col="orange")

3) Frequency polygon
x=scan()
> breaks=seq(1,21,4)
> class=cut(x,breaks,right=F)
> frequency=table(class)
> m1=breaks[-1];m2=breaks[-length(breaks)]
> m3=m2+(m1-m2)/2
> xx=c(breaks[1],m3,breaks[length(breaks)])
> yy=c(0,frequency,0)
> plot(xx,yy,col="red",pch=19,main="Frequency Polygon")
> lines(xx,yy,col="blue")

4) z-score for the data value 32


x=scan()
1: 32 17 14 25 28 30 10 17 18 26 25 22 16 17 19 26 11 29 14 24
21:
Read 20 items
> mean_data=mean(data)
> sd_data=sd(data)
> z_32=(32-mean_data)/sd_data; z_32
[1] 1.682641

5) Find the 20th and 80th percentiles.


x=scan()
1: 32 17 14 25 28 30 10 17 18 26 25 22 16 17 19 26 11 29 14 24
21:
Read 20 items
> quantile(x,0.8)
80%
26.4
6)Draw a boxplot and include the five-number summary in the boxplot

x=scan()
1: 32 17 14 25 28 30 10 17 18 26
11: 25 22 16 17 19 26 11 29 14 24
21:
Read 20 items
> fivenum(x)
[1] 10.0 16.5 20.5 26.0 32.0
> summary(x)
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.00 16.75 20.50 21.00 26.00 32.00
> boxplot(x,horizontal=T,axes=F,col="orange",border="darkgreen",lwd=2)
> axis(1,at=fivenum(x))
> quantile(x,0.8)
80%
26.4

7) The mean, the median and the mode

x=c(4,10,6,8,7,4,6,8,9,6)
> mean(x)
[1] 6.8
> median(x)
[1] 6.5
> table(x)
x
4 6 7 8 9 10
2 3 1 2 1 1
The mode is 6
8) The range, the variance, the standard deviation and the mean absolute deviation

x=c(4,10,6,8,7,4,6,8,9,6)
> range(x)
[1] 4 10
> var(x)
[1] 3.955556
> sd(x)
[1] 1.988858
mad=sum(abs(x-mean(x)))/length(x);mad
[1] 1.6
>

9) Histogram
x=scan
boundary=c(59.5 69.5 79.5 89.5 99.5 109.5 119.5 129.5)
boundary=seq(59.5,129.5,10)
colors=c(“yellow” “orange” “red” “pink” “green” “blue” “darkblue”)
hist(x,breaks=boundary,col=colors,main=”HISTOGRAM”)

10) Ogive

x=scan
boundary=c(19.5,29.5,39.5,49.5,59.5,69.5,79.5)
cumul.freq=c(0,0.6,0.25…..)
plot(boundary,cumul.freq,pch=19,col=”blue”,main=”ogive”)
lines(boundary,cumul,freq,col=”red”)

11)Pie chart

students=c(260,180,70,90)
names(students)=c(“freshman:\n43%”, “sophomore:\n30%”,”junior:\n12%”,”senior:\n15%”)
colours=c(“yellow”,”orange”,”red”,”green”)
pie(student,col=colours,main=”pie chart of the distribution of IUGB students”)

12) Bar Chart


student =c(260,180,70,90)
names(students)=c(“freshman”, “sophomore”, “junior”,“senior”)
colours=c(“yellow”, “orange”, “red”, “ green”)
barplot(student,col=colours,main= “My Bar chart”)
13) Outlier

x=scan()
iqr=fivenum(x)[4]-fivenum(x)[2]
11=min(x)-1.5*iqr
u1=max(x)+1.5*iqr
interval.normal=c(11,u1);interval.normal

Probability distribution

Bar plot probability distribution:

p=3/4 ; n=3 ; x=(0,1,2,3)


prob=dbinom(x,n,p)
cbind(x,prob)
names(prob)=c(“x=0”,”x=1”,”x=2”,”x=3”)
color=c(“white”, “pink”, “consilk”, “orange”)
barplot(prob,col=color,main= “probability distribution of x)

The variance of the random variable X

x=c(0,1,2)
pr=c(0.16,0.48,0.36 )
mean=sum(x*pr);mean
second_moment=sum(x^2)*pr);second_moment
var=second_moment-mean^2;var
std=sqrt(var);std
LL=mean-2*std; UL=mean+2*std
c(LL,UL)

● Pr(X=3)
n=4; x=3 ; P=0.1
dbinom(x,n,p)

Mean, variance of x , standard deviation ,interval of usual values

n=10; p=6
mean=n*p;var=n*p*(1-p);stdev=sqrt(var);interval=c(mean-2*stdev,mean+2*stdev)
mean
var
stdev
interval

● pr(X >3)=1-pr(X≤3)

mu=1.2
1-ppois(3,mu)

● pr(X≤4)
x=c(1,2,3,4)
sum(dbinom(x,1020,p=0.01))

● Pr(X=0)
n=1020 ; p=0.01 ; mu=n*p
dpois(0, mu)

Hypothesis Testing
● Right tail test

Test statistic

>x=1864
> n=2246
> phat=x/n
> p0=0.8
> q0=1-p0
> zcal=(phat-p0)/sqrt((p0*q0)/n)
> zcal
Or
x=1864;n=2246;p=x/n;p0=0.8;alpha=0.05
zcal=(p-p0)/sqrt((p0*q0)/n)

Critical values
alpha=0.05
zcr=qnorm(1-alpha);zcr
Or

zcr=qnorm(1-alpha);zcr

P-values

Nb = zcal is the test statistic


zcal = 3.54255
pvalue=1-pnorm(zcal);pvalue

Or

Pvalue=1-pnorm(3.5449);pvalue

● Left tail test

Test statistic

p=850/1200;p0=0.9;n=1200
zcal=(p-p0)/sqrt(p0*(1-p0)/n);zcal ( Attention)

Critical value

alpha=0.01
zcr=qnorm(alpha);zcr

P-value

zcal=-22.13176
pvalue=pnorm(zcal);pvalue

● Two tail test

Test statistic

p=589/745;p0=0.75;n=745
zcal=(p-p0)/sqrt(p0*(1-p0)/n);zcal

Critical value

alpha=0.01
cr1=qnorm(alpha/2)
cr2=qnorm(1-alpha/2)
c(cr1,cr2)

Pvalue

pvalue=2*pnorm(zcal)
pvalue
MEAN

● Right tail test

Test statistics
x=scan()
mean=mean(x);mean
sd=sd(x);sd
n=length(x);mu0=75
tcal=sqrt(n)*(mean-mu0)/sd;tcal

Critical values

alpha=0.01
tcr=qt(1-alpha,df=n-1);tcr

Pvalue

pvalue=1-pt(tcal,df=n-1);pvalue

● Left tail test

Test statistic

scan()
mean=mean(x)
sd=sd(x)
mu0=93
n=length(x)
tcal=sqrt(n)*(mean-mu0)/sd;tcal

Critical value

alpha=0.05
tcr=qt(alpha,df=n-1);tcr

Pvalue

pvalue=pt(tcal,df=n-1);pvalue
Two tail test

Test statics
x=scan
n=length
mean=mean(x);mean
s=sd(x);s
tcal=sqrt(n)*(mean-8.3)/s;tcal

Critical value

alpha=0.01
tcr1=qt(alpha/2,df=n-1);tcr2=qt(1-alpha/2,df=n-1)
c(tcr1,tcr2)

Pvalue

tcal=1.652333
pvalue=2*(1-pt(tcal,df=n-1));pvalue

Test statistics

𝑝−𝑝0
zcal=
𝑝0*(1−𝑃0
𝑛

Test statistic mean

𝑛(𝑥−µ0)
t= 𝑠
Correlation and regression

Coefficient correlation

> x=scan()
> y=scan()
> cor(x,y)
[1] 0.9594032

To test the significance of the correlation coefficient

cor.test(x,y)

If the p-value is greater than the level of significance alpha, we accept the null
hypothesis, there is no correlation between the variables. If p-value is very small,
less than alpha, there is a significant correlation between the variables

Scatter plot with R

> cpi=c(30.2,48.3,112.3,162.2,191.9,197.8)
> pizza=c(0.15,0.35,1.00,1.25,1.75,2.00)
> plot(cpi,pizza,pch=20,col="blue",main="scatter plot")

The coefficient of the correlation coefficient with R

r=cor(cpi,pizza);r

*
cor.test(cpi,pizza)

Note: If the p-value is less than 0.05, thèn we conclude that there is sufficient
evidence to support the claim of a linear correlation between consumer price index
and the cost of pizza.

You might also like