Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #EXO1
  2.  
  3. a<-c(3,5,7,11)
  4. a[2]
  5. a[1:3]
  6. a[a>5]
  7.  
  8. #EXO 2
  9.  
  10. stat.log <- function (x)
  11. {
  12. n<-length(x)
  13. s<-0
  14. for (i in (1:n)) {s<-s+x[i]}
  15. s/n
  16. }
  17.  
  18. stat.log(a)
  19.  
  20. #EXO 3
  21.  
  22. #a
  23.  
  24. echantillon <- rnorm (10,0,1)
  25. echantillon10 <- rnorm (50,0,1)
  26. echantillon11 <- rnorm (500,0,1)
  27. echantillon
  28. #b
  29.  
  30. echantillon2 <- rexp(10,0.1)
  31. echantillon2
  32.  
  33. echantillon3 <- rexp(50,0.1)
  34. echantillon3
  35.  
  36. echantillon4 <- rexp(500,0.1)
  37. echantillon4
  38.  
  39. #c
  40.  
  41. echantillon5 <- runif(10,0,1)
  42. echantillon5
  43.  
  44. echantillon6 <- runif(50,0,1)
  45. echantillon6
  46.  
  47. echantillon7 <- runif(500,0,1)
  48. echantillon7
  49.  
  50. #EXO4
  51.  
  52. produits <- c("Cancoillotte","Saucisse de Montbéliard","Edel de Clairon", "Saucisse de Morteau","Mont D'or","Vin jaune")
  53. chiffres <- c(1950,470,670,920,750,715)
  54.  
  55. pie (chiffres, labels = produits)
  56.  
  57. #EXO 5
  58.  
  59. barplot(chiffres,names = produits)
  60.  
  61. #EXO 6
  62.  
  63. enfants <- c("0","1","2","3","4","5","6",">6")
  64. freq <- c(235,183,285,139,88,67,3,0)
  65.  
  66. pie(freq,labels=enfants)
  67.  
  68. #EXO 7
  69.  
  70. #1
  71. echantillon8 <- c(91.6,35.7,251.3,24.3,5.4,67.3,170.9,9.5,118.4,57.1)
  72.  
  73. echantillon9 <- sort(echantillon8)
  74.  
  75. #2
  76.  
  77. hist(echantillon8,prob=F,breaks=seq(3,260,50))
  78.  
  79. #3
  80.  
  81. h<-hist(echantillon8,prob=T,breaks=c(3,15,50,90,160,260))
  82. abs<-h$mids
  83. abs
  84. #4
  85.  
  86.  
  87. lines(h$mids,h$density)
  88.  
  89. #EXO 8
  90.  
  91. h1 <- hist(echantillon,prob=T)
  92. h10 <- hist(echantillon10,prob=T)
  93. h11 <- hist(echantillon11,prob=T)
  94. h2 <- hist(echantillon2,prob=T,breaks=c(1,40,5))
  95. h3 <- hist(echantillon5,prob=T,breaks=c(0.1,1,0.2))
  96.  
  97. #EXO 9
  98.  
  99. #1 et 2
  100. x <- summary(a)
  101.  
  102. moyenne <- mean(x)
  103. variance <- var (x)
  104. mediane <- median(x)
  105. quartile <- quantile (x)
  106.  
  107. moyenne
  108. variance
  109. mediane
  110. quartile
  111.  
  112. #3
  113.  
  114. summary (echantillon2)
  115.  
  116.  
  117. # EXO 10
  118.  
  119. #1
  120.  
  121. val <- 1
  122. x<-seq(0,10,1)
  123. y<- -4*x+1+ rnorm(length(x),0,val)
  124.  
  125. plot(x,y)
  126.  
  127. #3
  128.  
  129. b0 <- mean(y)-cov(x,y)/var(x)*mean(x)
  130. b1 <- cov(x,y)/var(x)
  131. b0
  132. b1
  133. y1 <- b1*x+b0
  134.  
  135. plot(x,y1)
  136.  
  137. #4
  138. reg <- lm(y~x)
  139.  
  140. summary(reg)
  141.  
  142.  
  143. abline(reg)
  144.  
  145. coeff <- cor(x,y)
  146. coeff
  147.  
  148. erreurmoyenne <- function (x)
  149. {
  150. n <- length (x)
  151. m <- mean(x)
  152. erreurmoy2 <- 0
  153. for (i in(1:n)) {s <- (x[i]-m)^2}
  154. erreurmoy <- 1/n
  155. }
  156.  
  157. erreurmoyenne(x)
  158.  
  159. erreurmoy = var(y) - (1-cor(x,y))^2
  160. erreurmoy
  161.  
  162. #Exo11
  163.  
  164.  
  165. lines(density(echantillon11))
  166. plot(ecdf(echantillon11))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement