Téléverser les fichiers vers "/"
This commit is contained in:
49
script.R
Normal file
49
script.R
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
var1 = function(x) {
|
||||||
|
return(mean(x**2)-mean(x)**2)
|
||||||
|
}
|
||||||
|
|
||||||
|
var2 = function(x,n) {
|
||||||
|
return(weighted.mean(x**2,n)-weighted.mean(x,n)**2)
|
||||||
|
}
|
||||||
|
|
||||||
|
sd1 = function(x) {
|
||||||
|
return(sqrt(var1(x)))
|
||||||
|
}
|
||||||
|
|
||||||
|
sd2 = function(x,n) {
|
||||||
|
return(sqrt(var2(x,n)))
|
||||||
|
}
|
||||||
|
|
||||||
|
covariance = function(x,y){
|
||||||
|
return(sum((x-mean(x))*(y-mean(y)))/length(x))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# correlation = function(x, y) {
|
||||||
|
# return(covariance(x,y)/(sd1(x) * sd1(y)))
|
||||||
|
# }
|
||||||
|
|
||||||
|
droite_yx = function(x, y) {
|
||||||
|
m = covariance(x,y) / var1(x)
|
||||||
|
p = mean(y) - m*mean(x)
|
||||||
|
return (c(m, p))
|
||||||
|
}
|
||||||
|
|
||||||
|
droite_xy = function(x, y) {
|
||||||
|
m = covariance(x, y) / var1(y)
|
||||||
|
p = mean(x) - m * mean(y)
|
||||||
|
return (c(m, p))
|
||||||
|
}
|
||||||
|
|
||||||
|
reg_yx <- droite_yx(x, y)
|
||||||
|
reg_xy <- droite_xy(x, y)
|
||||||
|
|
||||||
|
plot(x, y,
|
||||||
|
main = "Régression Vitesse vs Distance de freinage",
|
||||||
|
xlab = "Vitesse (km/h)",
|
||||||
|
ylab = "Distance de freinage (m)",
|
||||||
|
pch = 19, col = "blue", cex = 1.2)
|
||||||
|
|
||||||
|
abline(a = reg_yx[2], b = reg_yx[1], col = "red", lwd = 1)
|
||||||
|
|
||||||
|
abline(a = -reg_xy[2]/reg_xy[1], b = 1/reg_xy[1], col = "purple", lwd = 1)
|
||||||
28
script_tp2.R
Normal file
28
script_tp2.R
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
series = matrix(0,100,20)
|
||||||
|
|
||||||
|
moyennes = c()
|
||||||
|
etypes = c()
|
||||||
|
|
||||||
|
for (i in 1:20) {
|
||||||
|
print(paste("--- Série",i))
|
||||||
|
|
||||||
|
data = runif(100)
|
||||||
|
|
||||||
|
series[,i] <- data
|
||||||
|
|
||||||
|
print(paste("Écart interquartile:",IQR(data)))
|
||||||
|
|
||||||
|
m = mean(data)
|
||||||
|
moyennes <- c(moyennes, m)
|
||||||
|
print(paste("Moyenne", m))
|
||||||
|
|
||||||
|
etype = sd(data)
|
||||||
|
etypes <- c(etypes, etype)
|
||||||
|
print(paste("Écart-Type:", etype))
|
||||||
|
}
|
||||||
|
|
||||||
|
boxplot(series,horizontal = FALSE)
|
||||||
|
|
||||||
|
print("--------------------")
|
||||||
|
print(paste("Moyenne des moyennes:",mean(moyennes)))
|
||||||
|
print(paste("Moyenne des ecart types",mean(etypes)))
|
||||||
15
script_tp3.R
Normal file
15
script_tp3.R
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
densite = c(8, 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 8.7, 8.8, 8.9, 9, 9.1)
|
||||||
|
effectif = c(4, 20, 43, 100, 200, 250, 190, 113, 50, 19, 6, 5)
|
||||||
|
data = data.frame(densite, effectif)
|
||||||
|
|
||||||
|
moyenne = sum(data$densite * data$effectif) / sum(data$effectif)
|
||||||
|
etype = sd(rep(data$densite, data$effectif))
|
||||||
|
|
||||||
|
percent_inside = function(borne_inf, borne_sup) {
|
||||||
|
data_intervalle = subset(data, densite >= borne_inf & densite <= borne_sup)
|
||||||
|
pourcentage = sum(data_intervalle$effectif) / sum(data$effectif) * 100
|
||||||
|
return(pourcentage)
|
||||||
|
}
|
||||||
|
|
||||||
|
print(percent_inside(moyenne - etype, moyenne + etype))
|
||||||
|
print(percent_inside(moyenne - 2 * etype, moyenne + 2 * etype))
|
||||||
21
script_tp4.R
Normal file
21
script_tp4.R
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
elements = runif(1000)
|
||||||
|
|
||||||
|
effectifs = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||||
|
keys = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||||
|
|
||||||
|
for (i in 0:9) {
|
||||||
|
borne_min = i/ 10
|
||||||
|
borne_max = (i + 1) / 10
|
||||||
|
|
||||||
|
for (e in elements) {
|
||||||
|
if (e >= borne_min && e <= borne_max) {
|
||||||
|
effectifs[i + 1] = effectifs[i + 1] + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
keys[i + 1] = i + 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
df = data.frame(keys, effectifs)
|
||||||
|
|
||||||
|
print(df)
|
||||||
Reference in New Issue
Block a user