# Check Arbeitsverzeichnis getwd() # Übersicht für Beispielsdatensätze data() # Wir schauen uns iris data(iris) # Explorativen Datenauswertung ---- pairs(iris) # Siehe auch https://r-charts.com/correlation/ggpairs/ # Beschreibung der Tabelle head(iris) tail(iris) summary(iris) str(iris) library(dplyr) glimpse(iris) # Nach tidyverse # Korrelationen --- iris %>% select(-Species) %>% cor() # Mit Faktor (dann Spearman anstatt Pearson) iris %>% mutate(Species = as.numeric(Species)) %>% cor(method = "spearman") # Lineare Regression ---- plot(Petal.Width ~ Petal.Length, data = iris) # Das gleiche mit ggplot library(ggplot2) ggplot(iris, aes(x = Petal.Length, y = Petal.Width, colour = Species)) + geom_point() # Lineare Regression model1 <- lm(Petal.Width ~ Petal.Length, data = iris) model1 summary(model1) # Inhalt des models model1$residuals str(summary(model1)) summary(model1)$r.squared # Weitere Funktionen für das Model resid(model1) # Residuen fitted(model1) # Am Model angepasste Antworten coef(model1) # Koeffiziente bzw. Parameter der Funktion predict(model1, data.frame(Petal.Length = 3)) # Vorhersage # Grafishe Darstellung des Models ---- ggplot(data = iris, aes(x = Petal.Length, y = Petal.Width)) + geom_point() + geom_abline(intercept = coef(model1)[1], slope = coef(model1)[2]) # Berechnung ntegriert in ggplot ggplot(data = iris, aes(x = Petal.Length, y = Petal.Width)) + geom_point() + geom_smooth(method = "lm") # Getrennt pro Art ggplot(data = iris, aes(x = Petal.Length, y = Petal.Width, colour = Species)) + geom_point() + geom_smooth(method = "lm")