Donnees Mathematique
Donnees Mathematique
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")
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
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”)
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
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)
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
Or
Pvalue=1-pnorm(3.5449);pvalue
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
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
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
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
𝑛
𝑛(𝑥−µ0)
t= 𝑠
Correlation and regression
Coefficient correlation
> x=scan()
> y=scan()
> cor(x,y)
[1] 0.9594032
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
> 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")
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.