Docsity
Docsity

Prepara i tuoi esami
Prepara i tuoi esami

Studia grazie alle numerose risorse presenti su Docsity


Ottieni i punti per scaricare
Ottieni i punti per scaricare

Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium


Guide e consigli
Guide e consigli


Cheat Sheet Informatica 2 SI22, Schemi e mappe concettuali di Elementi di Informatica

Una raccolta di comandi e formule utili per lavorare con matrici, vettori e dataset in R. Inoltre, vengono presentati esempi di grafici e istruzioni per l'ottimizzazione. utile per gli studenti di informatica che utilizzano R per l'analisi dei dati.

Tipologia: Schemi e mappe concettuali

2021/2022

In vendita dal 14/11/2023

ricc-va-2
ricc-va-2 🇮🇹

4

(1)

5 documenti

1 / 6

Toggle sidebar

Questa pagina non è visibile nell’anteprima

Non perderti parti importanti!

bg1
Cheat Sheet Informatica 2 SI22
Utilities:
getwd() : Find the current directory
setwd(‘path’) : Change the working directory
rm(x) : Remove x from the environment
rm(list = ls()) : Remove all variables
Matrix:
Create:
m <- matrix(x, nrow=3, ncol=3) : Creates a 3x3 matrix from x
rbind(x, y, z) : Bind rows
cbind(x, y, z) : Bind columns
Access:
m[2, ] : Select a row
m[ ,1] : Select a column
m[2, 3] : Select an element
Change:
m[rowldx, columnldx] <- 5.5 : Change one element
m <- m[ , -columnldx] : Delete one column
m <- c(m) : Convert to Vector
Matrix Calculus:
Addition: A + B addition of matrices of same dimension
Trace: matrix.trace(A)
Multiplication:
Matrix: A %*% B
Scalar: a * B
(row) vector * matrix: a = general, b = column, c = row
c %*% B
Matrix * (column) vector: B %*% b
(inner) product of 2 vectors → scalar: a = general, b = column, c = row
c %*% b
(outer) product of 2 vectors → matrix: b %*% c
Element-by-element: C <- A * B
Transpose: t(A)
Row ↔ Column vector: a = general, b = column, c = row
b <- t(c), b <- t(t(b))
Inverse Matrix: Check before if det not equal to 0, det(a) , then solve(A)
Sum of a Vector: a = general, b = column, c = row
rep(1, length(b)) %*% b
Sum of Squares: a = general, b = column, c = row
t(b) %*% b
c %*% t(c)
Covariance Matrix: N <- 1000, X <- matrix
N <- dim(x)[1] number of observations
Xbar <- colMeans(X) vector of means
1/(N-1)*t(X) %*% X - outer(Xbar, Xbar)
Rank: qr(X)$rank
Cheat Sheet Informatica 2 SI22
Plots:
Import/Install ggplot2 → library(ggplot2)/install.packages(ggplot2)
Bar Chart:
Standard One:
ggplot(data = grade, aes(x = country)) + geom_bar() + ggtitle("Student origin")
+ xlab("Country of origin") + ylab("Number of students")
Horizontal One:
ggplot(data = grade, aes(x = country)) + geom_bar() + coord_flip()
Pie Chart:
Bar Charts but with polar coordinates
emptyTheme <- theme(axis.text = element_blank(), axis.ticks = element_blank(),
panel.grid = element_blank())
ggplot(data = grade, aes(x = 1, fill = country)) + geom_bar() + coord_polar(theta =
"y") + emptyTheme + xlab("") + ylab("")
Doughnut Charts:
ggplot(data = grade, aes(x = 0.75, fill = country)) + geom_bar(width=0.5) +
xlim(c(0,1)) + coord_polar(theta = "y")
Scatter Plot:
ggplot(data = grade, aes(x = math, y = stat, color=gender, shape=country)) +
geom_point() + scale_color_manual(values=c("pink", "skyblue3")) +
scale_shape_manual(values=c(16, 3, 17)) + theme_minimal()
Line Chart:
ggplot(data = economics, aes(x = date, y = unemploy)) + geom_line()
Statistical Plots:
Boxplot: ggplot(data=grade, aes(x=gender, y=math)) + geom_boxplot() +
stat_boxplot(geom ='errorbar')
Histogram: ggplot(data=grade, aes(x=math, fill=gender)) +
geom_histogram(binwidth = 1, position = "dodge")
Density: ggplot(data=grade, aes(x=math, fill=gender)) +
geom_density(alpha=0.5)
Qqplot: ggplot(data=grade, aes(sample = econ))
+stat_qq(distribution=qnorm) + stat_qq_line()
pf3
pf4
pf5

Anteprima parziale del testo

Scarica Cheat Sheet Informatica 2 SI22 e più Schemi e mappe concettuali in PDF di Elementi di Informatica solo su Docsity!

Utilities: ● getwd() : Find the current directory ● setwd(‘path’) : Change the working directory ● rm(x) : Remove x from the environment ● rm(list = ls()) : Remove all variables

Matrix: ● Create: ○ m <- matrix(x, nrow=3, ncol=3) : Creates a 3x3 matrix from xrbind(x, y, z) : Bind rows ○ cbind(x, y, z) : Bind columns ● Access: ○ m[2, ] : Select a row ○ m[ ,1] : Select a column ○ m[2, 3] : Select an element ● Change: ○ m[rowldx, columnldx] <- 5.5 : Change one element ○ m <- m[ , -columnldx] : Delete one column ○ m <- c(m) : Convert to Vector

Matrix Calculus: ● Addition: A + B addition of matrices of same dimension ● Trace: matrix.trace(A) ● Multiplication: ○ Matrix: A %*% B ○ Scalar: a * B ○ (row) vector * matrix: a = general, b = column, c = row c %*% B ○ Matrix * (column) vector: B %*% b ○ (inner) product of 2 vectors → scalar: a = general, b = column, c = row c %*% b ○ (outer) product of 2 vectors → matrix: b %*% c ○ Element-by-element: C <- A * B ● Transpose: t(A) ● Row ↔ Column vector: a = general, b = column, c = row b <- t(c), b <- t(t(b)) ● Inverse Matrix: Check before if det not equal to 0, det(a) , then solve(A) ● Sum of a Vector: a = general, b = column, c = row rep(1, length(b)) %*% b ● Sum of Squares: a = general, b = column, c = row t(b) %% b c %% t(c) ● Covariance Matrix: N <- 1000, X <- matrix N <- dim(x)[1] number of observations Xbar <- colMeans(X) vector of means 1/(N-1)t(X) %% X - outer(Xbar, Xbar) ● Rank: qr(X)$rank

Plots: Import/Install ggplot2 → library(ggplot2)/install.packages(ggplot2) ● Bar Chart: ○ Standard One: _ggplot(data = grade, aes(x = country)) + geom_bar() + ggtitle("Student origin")

  • xlab("Country of origin") + ylab("Number of students")_ ○ Horizontal One: ggplot(data = grade, aes(x = country)) + geom_bar() + coord_flip() ● Pie Chart: Bar Charts but with polar coordinates emptyTheme <- theme(axis.text = element_blank(), axis.ticks = element_blank(), panel.grid = element_blank()) ggplot(data = grade, aes(x = 1, fill = country)) + geom_bar() + coord_polar(theta = "y") + emptyTheme + xlab("") + ylab("") ● Doughnut Charts: ggplot(data = grade, aes(x = 0.75, fill = country)) + geom_bar(width=0.5) + xlim(c(0,1)) + coord_polar(theta = "y") ● Scatter Plot: ggplot(data = grade, aes(x = math, y = stat, color=gender, shape=country)) + geom_point() + scale_color_manual(values=c("pink", "skyblue3")) + scale_shape_manual(values=c(16, 3, 17)) + theme_minimal() ● Line Chart: ggplot(data = economics, aes(x = date, y = unemploy)) + geom_line() ● Statistical Plots: ○ Boxplot: ggplot(data=grade, aes(x=gender, y=math)) + geom_boxplot() + stat_boxplot(geom ='errorbar') ○ Histogram: ggplot(data=grade, aes(x=math, fill=gender)) + geom_histogram(binwidth = 1, position = "dodge") ○ Density: ggplot(data=grade, aes(x=math, fill=gender)) + geom_density(alpha=0.5) ○ Qqplot: ggplot(data=grade, aes(sample = econ)) +stat_qq(distribution=qnorm) + stat_qq_line()

Work with Data: Vectors

Datasets

Optimization:

Functions and Loops pt. 2

Fibonacci <- numeric(10) Fibonacci[1] <- Fibonacci[2] <- 1 for (i in 3:10) {Fibonacci[i] <- Fibonacci[i - 2] + Fibonacci[i - 1]} print("First 10 Fibonacci numbers:") print(Fibonacci)

Tribonacci <- numeric(10) Tribonacci[1] <- 1 Tribonacci[2] <- 1Tribonacci[3] <- 1 for (i in 4:10) {Tribonacci[i] <- Tribonacci[i - 3] + Tribonacci[i - 2] + Tribonacci[i - 1]} print("First 10 Tribonacci numbers:") print(Tribonacci)

Matrix Calculus:

Matrix Calculus pt.2: LateX: