Analyse du prix des maisons
> x
 [1] 168000 182700 205000 135000 158167 184000 234000 165000 380000 148000
[11] 140000 180000 174000 169000 140000 165000 157000 170000 300000 475000
[21] 255000 125000 140070 177380 180000 127000 133000 215000 175000 135000
[31] 160000 500000

> mean(x)
[1] 198509.9

> sqrt(var(x)/length(x))
[1] 16297.25

> qt(.025,length(x)-1)
[1] -2.039513

> qt(.975,length(x)-1)
[1] 2.039513

> c(mean(x)-qt(.975,length(x)-1)*sqrt(var(x)/length(x)),
+ mean(x)-qt(.025,length(x)-1)*sqrt(var(x)/length(x)))
[1] 165271.4 231748.4


> t.test(x)  

    One-sample t-Test 

data:  x 
t = 12.1806, df = 31, p-value = 0 
alternative hypothesis: true mean is not equal to 0 
95 percent confidence interval:
 165271.4 231748.4 
sample estimates:
 mean of x 
  198509.9

> qqnorm(x,main="Graphique quantiles normaux de x")

> maison.1999
 Ahunstic  Anjou Beaconsfield Beloeil Blainville Boucherville Brossard 
   168000 182700       205000  135000     158167       184000   234000
 Chomedey Cote St-Luc Dorval Fabreville Hudson Kirkland Lachine Lasalle 
   165000      380000 148000     140000 180000   174000  169000  140000
 Laval-Des-Rapides Longueuil Lorraine Montreal Ouest Mont-Royal 
            165000    157000   170000          3e+05     475000
 Notre-Dame-de Grace Pierrefonds Repentigny Rosemere St-Bruno St-Eustache 
              255000      125000     140070   177380   180000      127000
 St-Hubert St-Lambert St-Laurent Ste-Therese Vimont Westmount 
    133000     215000     175000      135000 160000     5e+05

> stem(maison.1999)

N = 32   Median = 169500
Quartiles = 144035, 194500

Decimal point is 4 places to the right of the colon

   12 : 57
   13 : 355
   14 : 0008
   15 : 78
   16 : 05589
   17 : 0457
   18 : 0034
   19 :
   20 : 5
   21 : 5
   22 :
   23 : 4
   24 :
   25 : 5

High:  300000  380000  475000  500000

> hist(maison.1999,main="Histogramme du prix des maisons",
+ sub="Prix en octobre 1999")



> maison.1999.analyse_bootstrap(maison.1999,median,B=999)
Forming replications  1  to  100
Forming replications  101  to  200
Forming replications  201  to  300
Forming replications  301  to  400
Forming replications  401  to  500
Forming replications  501  to  600
Forming replications  601  to  700
Forming replications  701  to  800
Forming replications  801  to  900
Forming replications  901  to  999

> maison.1999.analyse
Call:
bootstrap(data = maison.1999, statistic = median, B = 999)

Number of Replications: 999

Summary Statistics:
       Observed  Bias   Mean   SE
median   169500 552.5 170052 5505


> summary(maison.1999.analyse)
Call:
bootstrap(data = maison.1999, statistic = median, B = 999)

Number of Replications: 999

Summary Statistics:
       Observed  Bias   Mean   SE
median   169500 552.5 170052 5505

Empirical Percentiles:
         2.5%     5%    95%  97.5%
median 158483 160000 180000 180002

BCa Confidence Limits:
         2.5%     5%    95%  97.5%
median 157584 159084 178690 180000


> plot(maison.1999.analyse)
> qqnorm(maison.1999.analyse)


> maison.1999.analyse4_bootstrap(maison.1999,mean,B=999)
Forming replications  1  to  100
Forming replications  101  to  200
Forming replications  201  to  300
Forming replications  301  to  400
Forming replications  401  to  500
Forming replications  501  to  600
Forming replications  601  to  700
Forming replications  701  to  800
Forming replications  801  to  900
Forming replications  901  to  999

> maison.1999.analyse4
Call:
bootstrap(data = maison.1999, statistic = mean, B = 999)

Number of Replications: 999

Summary Statistics:
     Observed  Bias   Mean    SE
mean   198510 471.2 198981 16035

> summary(maison.1999.analyse4)
Call:
bootstrap(data = maison.1999, statistic = mean, B = 999)

Number of Replications: 999

Summary Statistics:
     Observed  Bias   Mean    SE
mean   198510 471.2 198981 16035

Empirical Percentiles:
       2.5%     5%    95%  97.5%
mean 171526 174396 227512 232473

BCa Confidence Limits:
       2.5%     5%    95%  97.5%
mean 173861 176702 231987 242395

> sqrt(var(maison.1999)/length(maison.1999))
[1] 16297.25

> sqrt(31/32)*16297.25
[1] 16040.58

> plot(maison.1999.analyse4)
> qqnorm(maison.1999.analyse4)



> tempo1_as.numeric(length=263)
> for(i in 1:length(tempo))
+ tempo1[i]_mean(dnorm(tempo[i],maison.1999,15625/2))
> tempo2_as.numeric(length=263)
> for(i in 1:length(tempo))
+ tempo2[i]_mean(dnorm(tempo[i],maison.1999,20000))
> tempo3_as.numeric(length=263)
> for(i in 1:length(tempo))
+ tempo3[i]_mean(dnorm(tempo[i],maison.1999,30000))
> plot(tempo,tempo1)
> lines(tempo,tempo2)
> lines(tempo,tempo3,lty=3)
> par(mfrow=c(3,1))
> plot(tempo,tempo1,type="l")
> plot(tempo,tempo2,type="l")
> plot(tempo,tempo3,type="l")
> tempo1[73]
[1] 1.477673e-05
> tempo2[73]
[1] 1.0213e-05
> tempo3[73]
[1] 8.37587e-06
> 1/(4*32*tempo1[73]^2)
[1] 35779426
> sqrt(1/(4*32*tempo1[73]^2))
[1] 5981.591
> sqrt(1/(4*32*tempo2[73]^2))
[1] 8654.497
> sqrt(1/(4*32*tempo3[73]^2))
[1] 10552.74
> densite.maison99_list(x=tempo,y7812.5=tempo1,y20000=tempo2,y30000=tempo3)
> par(mfrow=c(3,1))
> plot(densite.maison99$x,densite.maison99$y30000, 
+ main="Fenêtre = 30 000; Écart type de la médiane = 10 552,74",xlab="Prix",
+ ylab="Densité",type="l")
> plot(densite.maison99$x,densite.maison99$y20000, 
+ main="Fenêtre = 20 000; Écart type de la médiane = 8 654,497",xlab="Prix",
+ ylab="Densité",type="l")
> plot(densite.maison99$x,densite.maison99$y7812.5,
+ main="Fenêtre par défaut (7 812,5); Écart type de la médiane = 5 981,591",
+ xlab="Prix",ylab="Densité",type="l")
> par(mfrow=c(1,1))
> plot(c(0,600000),c(0,1),type="n",xlab="Prix",ylab="Probabilité",
+ main="Fonction de répartition expérimentale du prix des maisons",
+ sub="Octobre 1999")
> lines(c(0,min(maison.1999)),c(0,0))
> lines(c(max(maison.1999),600000),c(1,1))
> for(i in 2:length(maison.1999))
+ lines(c(sort(maison.1999)[i-1],sort(maison.1999)[i]),
+ c((i-1)/length(maison.1999),(i-1)/length(maison.1999)))