Skip to content
Prev 392036 / 398500 Next

R for linear algebra

Just adding to my previous post, I looked back and this forum has at times?had discussions in which the use of packages related to R STUDIO and/or?the tidyverse was considered somehow not aligned with the mailing list.?

Many of the above are, in MY opinion, way more relevant to people using R?in their daily lives as some are very popular packages.

I am not saying a package focused on teaching Linear Algebra is not useful?or that the audience is limited. I was saying that R was partially designed?specifically for many things done in linear Algebra to be doable in relatively?few steps and thus a hospitable place all on it's own and a great place to host?such an add-on package.

In my experience, though, most packages and modules out there do not stand?alone. For serious uses, you must glue together various parts of what the?package supplies with fairly routine code such as to read in data and?convert it to the form needed, or to use results in other packages and so on.

So my earlier replies were focused far wider on R indeed being a hospitable?environment regardless of any specific packages supplied that zoomed in?on parts of a specialized field of endeavor. I am glad someone supplied one?such package for consideration but I also think a course could be taught?where most of the functionality needed was from base R and some other?packages already widely used except perhaps for some esoteric parts.

Just as a BTW, I have seen packages that use a GUI to automate loading?in data, applying various transformations and analyses on it and producing?some kinds of output. Much of it is checkboxes and the like. But the part of it?that I appreciated the most was that it was able to show you the underlying?R code it generated which you could copy and modify for all kinds of?additional needs you may have that the GUI did not cover or that ...

Some tools need not replace but augment and for professionals, it can be?better to be able to see what is going on under the hood, especially if?problems arise.

So if the class being taught is to people who will continue using it for years, I?might teach it differently as compared to those just needing three credits. It?is sort of like the multiple tracks I have seen for undergraduate classes in?a subject like Physics. My school had classes with or without derivations?and Calculus and other math so some just had equations thrown at them?and others got to understand why those equations worked the way they did?and how they were "invented" and how to make others with some thought?and so on. But it seems some schools now have a third track called?something like "Physics for Poets" which cuts back on even showing?too many equations!

Linear Algebra and R can also be taught at multiple levels and being a purist,?my preference is to UNDERSTAND things not just on the surface. But most?people who are just passing by do not really need to learn much of it, let?alone all of it. Yet it becomes very sad when some such cruisers later on?decide to stick around and do additional sloppy work using what little?they know or making R do things as similar to the methods they used?in some other programming language.

That is part of why I made comments about the package as to whether?it really is something people should continue to use heavily if they want?to do lots of work in the field.?


-----Original Message-----
From: Avi Gross via R-help <r-help at r-project.org>
Cc: r-help at r-project.org <r-help at r-project.org>
Sent: Sat, Jun 25, 2022 2:09 pm
Subject: Re: [R] R for linear algebra

John,

I am not in any way disparaging the matlib package and it seems well-built for the?limited purpose of teaching Linear Algebra rather than R. It is probably a?better answer to a question about how to teach linear algebra while making?some more complex tasks doable. I recall the frustration of multiplying matrices?by hand as well as other operations, necessarily on smaller matrices.

My comments were more along the lines of the charter of this group which?seems far narrower. Yes, people can ask for suggestions for a package?that does something that may interest them but getting help on any one of?thousands of such packages here would get overwhelming.
-----Original Message-----
From: John Fox <jfox at mcmaster.ca>
To: Avi Gross <avigross at verizon.net>
Cc: r-help at r-project.org <r-help at r-project.org>
Sent: Sat, Jun 25, 2022 1:34 pm
Subject: Re: [R] R for linear algebra

Dear Avi,

The purpose of the matlib package is to *teach* linear algebra and 
related topics, not to replace or even compete with similar 
functionality in base R.

Consider, e.g., the following example for matlib::Inverse(), which 
computes matrix inverses by Gaussian elimination (I've elided most of 
the steps):

 > example("Inverse")

Invers>? A <- matrix(c(2, 1, -1,
Invers+? ? ? ? ? ? ? ? -3, -1, 2,
Invers+? ? ? ? ? ? ? ? -2,? 1, 2), 3, 3, byrow=TRUE)

Invers>? Inverse(A)
? ? ? [,1] [,2] [,3]
[1,]? ? 4? ? 3? -1
[2,]? -2? -2? ? 1
[3,]? ? 5? ? 4? -1

Invers>? Inverse(A, verbose=TRUE, fractions=TRUE)

Initial matrix:
? ? ? [,1] [,2] [,3] [,4] [,5] [,6]
[1,]? 2? ? 1? -1? ? 1? ? 0? ? 0
[2,] -3? -1? ? 2? ? 0? ? 1? ? 0
[3,] -2? ? 1? ? 2? ? 0? ? 0? ? 1

row: 1

? exchange rows 1 and 2
? ? ? [,1] [,2] [,3] [,4] [,5] [,6]
[1,] -3? -1? ? 2? ? 0? ? 1? ? 0
[2,]? 2? ? 1? -1? ? 1? ? 0? ? 0
[3,] -2? ? 1? ? 2? ? 0? ? 0? ? 1

? multiply row 1 by -1/3
? ? ? [,1] [,2] [,3] [,4] [,5] [,6]
[1,]? ? 1? 1/3 -2/3? ? 0 -1/3? ? 0
[2,]? ? 2? ? 1? -1? ? 1? ? 0? ? 0
[3,]? -2? ? 1? ? 2? ? 0? ? 0? ? 1

? multiply row 1 by 2 and subtract from row 2
? ? ? [,1] [,2] [,3] [,4] [,5] [,6]
[1,]? ? 1? 1/3 -2/3? ? 0 -1/3? ? 0
[2,]? ? 0? 1/3? 1/3? ? 1? 2/3? ? 0
[3,]? -2? ? 1? ? 2? ? 0? ? 0? ? 1


. . .


? multiply row 3 by 2/5 and subtract from row 2
? ? ? [,1] [,2] [,3] [,4] [,5] [,6]
[1,]? 1? ? 0? ? 0? ? 4? ? 3? -1
[2,]? 0? ? 1? ? 0? -2? -2? ? 1
[3,]? 0? ? 0? ? 1? ? 5? ? 4? -1
? ? ? [,1] [,2] [,3]
[1,]? ? 4? ? 3? -1
[2,]? -2? -2? ? 1
[3,]? ? 5? ? 4? -1

And similarly for the other functions in the package. Moreover, the 
functions in the package are transparently programmed in R rather than 
calling (usually more efficient but relatively inaccessible) compiled 
code, e.g., in a BLAS.

Best,
? John
On 2022-06-24 9:57 p.m., Avi Gross via R-help wrote: