Dear Avi,
On 2022-06-25 2:09 p.m., Avi Gross via R-help wrote:> 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.
> From what you said though, others looking for a package to use for?real
projects might well beware as it may indeed not be particularly?fast or in some
cases perhaps not as flexible.
As would be clear from the documentation -- e.g., from the Details
section of ?Inverse: "The method is purely didactic: The identity
matrix, I, is appended to X, giving [X | I]. Applying Gaussian
elimination gives [I | X^{-1}], and the portion corresponding to X^{-1}
is returned."
Best,
John
>
> -----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:
>> Yes, Michael, packages like matlib will extend the basic support within
base R and I was amused at looking at what the package supported that I had not
thought about in years!
>> https://www.rdocumentation.org/packages/matlib/versions/0.9.5
>> However, once you through in packages/modules/libraries and other
add-ons, I suggest many languages share such gifts that then allow a serious
amount of what we call linear Algebra to be done, albeit with some work.
>> In some ways my review of Linear Algebra in recent years showed me that
some things have changed from when I took it as part of a math degree in college
but a big change has been in finding so many uses of it now that computers can
do complicated things fast and even faster when using vectors and matrices as a
way to organize and consolidate operations, sometimes even in parallel.
>> Packages can be nice and especially if they gather together lots of
related functions to teach a subject but anyone doing serious work should first
make sure they know what is in the base.
>> If your matrix is A, you could load a package like psych to get a trace
of A:
>> psych::tr(A)
>> Or install? matlib with oodles of dependencies
>>
>> matlib::tr(A)
>> Or without worrying if the user had installed and made available a
library, use built-ins like diag() and sum():
>> sum(diag(A))
>> And what does??matlib::Det(A) gain you most of the time that det(A)
does not tell you?
>> A policy of this forum is to point out mostly what is part of standard
R and obviously there can??be specialized functionality in packages, albeit some
functions? in that package are unlikely to be taught in a first undergraduate
Linear Algebra course. I note matlib is billed as also?being for learning
Multivariate Statistics, and that is fine, just perhaps a tad of overkill.
>> If the users have a question about the base R functionality, they can
ask about it here. But if they want to know why the cholesky function in matlib
is not working for them, ...
>>
>>
>>
>> -----Original Message-----
>> From: Michael L Friendly <friendly at yorku.ca>
>> To: org (R-help at r-project.org) <r-help at r-project.org>
>> Cc: Avi Gross <avigross at verizon.net>; abouelmakarim1962 at
gmail.com>, <abouelmakarim1962 at gmail.com>
>> Sent: Fri, Jun 24, 2022 9:12 pm
>> Subject: Re: R for linear algebra
>>
>> ? <!--#yiv2977149432 _filtered {} _filtered {}#yiv2977149432
#yiv2977149432 p.yiv2977149432MsoNormal, #yiv2977149432
li.yiv2977149432MsoNormal, #yiv2977149432 div.yiv2977149432MsoNormal
{margin:0in;font-size:11.0pt;font-family:"Calibri",
sans-serif;}#yiv2977149432 a:link, #yiv2977149432 span.yiv2977149432MsoHyperlink
{color:#0563C1;text-decoration:underline;}#yiv2977149432
p.yiv2977149432MsoPlainText, #yiv2977149432 li.yiv2977149432MsoPlainText,
#yiv2977149432 div.yiv2977149432MsoPlainText
{margin:0in;font-size:11.0pt;font-family:"Calibri",
sans-serif;}#yiv2977149432 span.yiv2977149432EmailStyle17
{font-family:"Calibri", sans-serif;color:windowtext;}#yiv2977149432
span.yiv2977149432PlainTextChar {font-family:"Calibri",
sans-serif;}#yiv2977149432 .yiv2977149432MsoChpDefault
{font-family:"Calibri", sans-serif;} _filtered {}#yiv2977149432
div.yiv2977149432WordSection1 {}-->Hello? ? The {matlib} package was
developed for just this purpose ? teaching and illustrating linear algebra
concepts and techniques. In my old 6140 Multivariate Data Analysis course, I
spent ~5-6 weeks on linear algebra.? ? CRAN:
https://cran.r-project.org/web/packages/matlib/index.html GitHub:
https://github.com/friendly/matlib 6140:
http://euclid.psych.yorku.ca/www/psy6140/ ? There are quite a few vignettes? ?
--- Michael Friendly???? Email: friendly AT yorku DOT ca Professor, Psychology
Dept York University????? Voice: 416 736-2100 x66249 4700 Keele Street???
Web:http://www.datavis.ca | @datavisFriendly Toronto, ONT? M3J 1P3 CANADA? ?? ??
? Message: 11 Date: Fri, 24 Jun 2022 02:31:24 +0000 (UTC) From: Avi Gross
<avigross at verizon.net> To: "abouelmakarim1962 at gmail.com"
<abouelmakarim1962 at gmail.com>, ?????????????? "r-help at
r-project.org" <r-help at r-project.org> Subject: Re: [R] R for
Linear Algebra Message-ID: <1658548037.4476854.1656037884865 at
mail.yahoo.com> Content-Type: text/plain; charset="utf-8"? ? R is a
language specially made to do many things with vectors and matrices and arrays
with any reasonable?number of dimensions and also has a host of functions that
do things like make diagonal matrices, calculate?determinants and multiply them
in several ways,??invert them, get eigenvalues and much more if you look
for?packages. So the question becomes, what else do you feel you need for a
Linear Algebra course that a simple web?search would not have found like this:
https://towardsdatascience.com/intro-to-r-linear-algebra-2a4de2506c93 ?
https://towardsdatascience.com/intro-to-r-linear-algebra-2a4de2506c93#:~:text=R%20is%20especially%20handy%20with,solvers%20and%20dynamic%20indexing%20capabilities.
Unless I missed something, yes, R is more easily able to be used to do such
things than many other languages albeit?just about any language tends to have
access to a variety of functions that may do these things but are not?built in.?
?? ? -----Original Message----- From: AbouEl-Makarim Aboueissa
<abouelmakarim1962 at gmail.com> To: R mailing list <r-help at
r-project.org> Sent: Thu, Jun 23, 2022 10:39 am Subject: [R] R for Linear
Algebra? ? Re: R for Linear Algebra? ?? ?? ? Dear All:? ?? ?? ?? ?? ? In my STA
591 topics in Biostatistics Fall 2022, I am planning to spend about 5 weeks on
Linear Algebra.? ?? ?? ? I am wondering if someone has or knows the source for
some R functions/programs written for linear algebra calculations.? ?? ?? ? Also
if you know a book in Linear Algebra with R, will be a good help too.? ?? ? Any
help in this matter is highly appreciated in advance.
>> ??? [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
--
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/