SOCR ≫ DSPA ≫ DSPA2 Topics ≫

1 How is matrix multiplication defined?

Validate that \((A_{k,n}\times B_{n,m})^t = (B^t_{m,n})\times (A^t_{n,k})\), both using math notation (first principles) and using R functions for some example matrices.

2 Scalar vs. Matrix Multiplication

Demonstrate the differences between the scalar multiplication (\(*\)) and matrix multiplication (\(\%*\%\)).

3 Matrix Equations

Write a simple matrix solver (\(b = Ax\), i.e.,\(x= A^{-1}b\)) and validate its accuracy using the R command solve(A,b). Solve this equation.

\[\begin{align*} 2a - b + 2c &= 5\\ -a - 2b + c &= 3\\ a + b - c &= 2 \end{align*}.\]

4 Least Square Estimation

Use the SOCR Knee Pain dataset, extract the RB = Right-Back locations \((x,y)\), and fit in a linear model for vertical location (\(y\)) in terms of the horizontal location (\(x\)). Display the linear model on top of the scatter plot of the paired data.

5 Matrix manipulation

Create a matrix \(A\) with elements seq(1, 15, length = 6) and argument nrow = 3, add a row to this matrix; add two columns to A to obtain a new matrix \(C_{4,4}\). Then generate a diagonal matrix \(D\) with \(dim = 4\) and elements rnorm(4,0,1). Apply element wise addition, subtraction, multiplication and division to the matrices \(C\) and \(D\). Apply matrix multiplication to \(D\) and \(C\). Obtain the inverse of \(C\) and compare the result to ginv().

6 Matrix Transposition

Validate the multiplicative transpose formula (\((A_{k,n}\cdot B_{n,m})^{T} = (B_{n,m})^{T}\cdot (A_{k,n})^{T}\)), both using math notation, as well as using R calls, e.g., you can try A = matrix(1:6,nrow=3), B = matrix(2:7, nrow = 2).

7 Sample Statistics

Use the SOCR Data Iris Sepal Petal Classes to compute sample mean and variance of each variables. Then calculate the sample covariance - use both math notation and R built-in functions.

8 Eigenvalues and Eigenvectors

Generate a random matrix with A = matrix(rnorm(9,0,1),nrow = 3), compute the eigenvalues and eigenvectors for \(A\). Then try to solve this equation \(det(A-\lambda I) = 0\), where \(\lambda\) is a vector of length \(3\). Compare \(\lambda\) and the eigenvalues you computed above.

Example of manual and automated calculations of eigen-spectra (eigen-values and eigen-vectors)

# A <- matrix(rnorm(9,0,1),nrow = 3); A # define a random design matrix, may generate complex solutions A <- matrix(c(0,1/4,1/4,3/4,0,1/4,1/4,3/4,1/2),3,3,byrow=T); A eigen_spectrum <- eigen(A); eigen_spectrum # compute the eigen-spectrum (eigen-values, \(l\), and eigen-vectors, \(v\)), $ A v = l v\(. B <- A-eigen(A)\)valuesdiag(3); B # compute B = (A - eigen_value I) det(A-eigen(A)$valuesdiag(3)) # verify that the det(A-eigen(A)$valuesdiag(3)) is not trivial (\(0\)) A%%eigen(A)\(vector - eigen(A)\)valuediag(3) # validate that $ A v = l v\(. all.equal(A, eigen(A)\$vector %*% diag(eigen(A)\$values) %*% solve(eigen(A)\)vector)) # compare A = vlinv(v) all.equal(diag(3), A%%eigen(A)\(vector - eigen(A)\)values * eigen(A)$vector) # The last line compares I == AV - lambda*v, mind the \(*\) and \(%*%\) scalar and matrix operators

9 Regression Forecasting using Numerical Data

Use the Quality of Life data (Case06_QoL_Symptom_ChronicIllness) to fit several different Multiple Linear Regression models predicting clinically relevant outcomes, e.g., Chronic Disease Score.

  • Summarize and visualize the data using summary, str, pairs.panels, ggplot, and plot_ly().
  • Report paired correlations for numeric data and try to visualize these (e.g., heatmap, pairs plot, etc.)
  • Examine potential dependencies of the predictors and the dependent response variables
  • Fit a Multiple Linear Regression model, report the results, and explain the summary, residuals, effect-size coefficients, and the coefficient of determination, \(R^2\)
  • Draw model diagnostic plots, at least QQ plot, residuals plot and leverage plot (half norm plot)
  • Predict outcomes for new data
  • Try to improve the model performance using the step function based on AIC and BIC.
  • Fit a regression tree model and compare it with OLS model.
  • Try to use M5P to improve the model.
SOCR Resource Visitor number Web Analytics SOCR Email