File:Regression plane avec R.svg
| Uploaded by | Cdang |
|---|---|
| Upload date | 2013-08-27T14:07:32Z |
| MIME type | image/svg+xml |
| Dimensions | 268 × 240 px |
| File size | 19.0 KB |
Summary
| Description |
Français : Régression linéaire à 3 dimensions avec GNU R (modifié avec Inkscape). English: 3-demensional linear regression with GNU R (modified with Inkscape). |
| Date | |
| Source | Own work |
| Author | Cdang |
| SVG development | |
| Source code | R code# Création des données
# nombre de valeurs de chaque variable explicative
n <- 5
# variables explicative
x1 <- seq(0, 1, length.out = n)
x2 <- seq(0, 1, length.out = n)
# répétition des valeurs pour mixer x1 et x2
x1.data <- rep(x1, each = n)
x2.data <- rep(x2, n)
# variable expliquée
y = 1 + 2*x1.data + 3*x2.data + rnorm(n^2, 0, 0.4)
# ******************************
# régression des moindres carrés
donnees <- data.frame(x1.data, x2.data, y)
modele <- lm(y ~ ., donnees)
print("Modèle des moindres carrés : ")
print(modele)
# ************************
# représentation graphique
# tracé des données
VT <- persp(x1, x2, matrix(y, n, n))
# tracé des intersections du plan modèle
mx1 <- min(x1) ; mx2 <- min(x2)
Mx1 <- max(x1) ; Mx2 <- max(x2)
Minit <- trans3d(mx1, mx2, b0, VT)
Mzx <- trans3d(Mx1, mx2, fitted(modele)[n], VT)
Myz <- trans3d(mx1, Mx2, fitted(modele)[n*(n-1)+1], VT)
lines(c(Minit[1], Mzx[1]), c(Minit[2], Mzx[2]), lwd = 2)
lines(c(Minit[1], Myz[1]), c(Minit[2], Myz[2]), lwd = 2)
|
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.