Symbolic inverse of a matrix in R - r

How can I find the symbolic inverse of a matrix in R; for example:
Matrix.test <- function(x) matrix(c(x, x^2, x^3, x^4, x^5, x^6, x^7, x^8, x^9, 2*x, 3*x, 4*x, 2*x^2, 3*x^3, 4*x^4, 5*x^5), 4, 4)
I Know there is a package called 'Ryacas' which is an interface to 'yacas', but I could not apply it to do such this computations.
'yacas' is a program for symbolic manipulation of mathematical expressions.
Please see link for more details.
thank you

It works fine for me:
> library(Ryacas)
> x <- Sym('x')
> M <- List(List(1,x),List(x,1))
> PrettyForm(M)
/ \
| ( 1 ) ( x ) |
| |
| ( x ) ( 1 ) |
\ /
> PrettyForm(Inverse(M))
/ \
| / 1 \ / -( x ) \ |
| | ------ | | ------ | |
| | 2 | | 2 | |
| \ 1 - x / \ 1 - x / |
| |
| / -( x ) \ / 1 \ |
| | ------ | | ------ | |
| | 2 | | 2 | |
| \ 1 - x / \ 1 - x / |
\ /

And following on:
M2 <- List(List( x, x^2, x^3, x^4),
List( x^5, x^6, x^7, x^8),
List( x^9, 2*x ,3*x , 4*x),
List(2*x^2, 3*x^3, 4*x^4, 5*x^5))
Inverse(M2)
The answer's pretty complicated, though (I could only be bothered to re-format the first four lines):
{{(x^6*3*x*5*x^5-x^6*4*x*4*x^4+x^8*2*x*4*x^4-x^7*2*x*5*x^5+
x^7*4*x*3*x^3-x^8*3*x*3*x^3)/(x^7*3*x*5*x^5-x^7*4*x*4*x^4-
x^8*2*x*5*x^5+x^8*4*x*3*x^3-x^9*3*x*3*x^3+x^9*3*x*3*x^3+
x^8*2*x*5*x^5-x^8*4*x*3*x^3-x^7*3*x*5*x^5+x^7*4*x*4*x^4-
x^19*4*x^4+x^19*4*x^4+x^18*5*x^5-x^9*4*x*2*x^2-x^18*5*x^5+x^9*4*x*2*x^2-x^11*2*x*2*x^2+x^11*2*x*2*x^2),(x^4*3*x*3*x^3-x^4*2*x*4*x^4+x^3*2*x*5*x^5-x^3*4*x*3*x^3-x^2*3*x*5*x^5+x^2*4*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9*3*x*3*x^3+x^9*3*x*3*x^3+x^8*2*x*5*x^5-x^8*4*x*3*x^3-x^7*3*x*5*x^5+x^7*4*x*4*x^4-x^19*4*x^4+x^19*4*x^4+x^18*5*x^5-x^9*4*x*2*x^2-x^18*5*x^5+x^9*4*x*2*x^2-x^11*2*x*2*x^2+x^11*2*x*2*x^2),(x^8*3*x^3-x^7*4*x^4-x^8*3*x^3+x^7*4*x^4-x^9*2*x^2+x^9*2*x^2)/(x^7*3*x*5*x^5-x^7*4*x*4*x^4-x^8*2*x*5*x^5+x^8*4*x*3*x^3-x^9*3*x*3*x^3+x^9*3*x*3*x^3+x^8*2*x*5*x^5-x^8*4*x*3*x^3-x^7*3*x*5*x^5+x^7*4*x*4*x^4-x^19*4*x^4+x^19*4*x^4+x^18*5*x^5-x^9*4*x*2*x^2-x^18*5*x^5+x^9*4*x*2*x^2-x^11*2*x*2*x^2+x^11*2*x*2*x^2),(x^7*3*x-x^8*2*x+x^8*2*x-x^7*3*x)/(x^7*3*x*5*x^5-x^7*4*x*4*x^4-x^8*2*x*5*x^5+x^8*4*x*3*x^3-x^9*3*x*3*x^3+x^9*3*x*3*x^3+x^8*2*x*5*x^5-x^8*4*x*3*x^3-x^7*3*x*5*x^5+x^7*4*x*4*x^4-x^19*4*x^4+x^19*4*x^4+x^18*5*x^5-x^9*4*x*2*x^2-x^18*5*x^5+x^9*4*x*2*x^2-x^11*2*x*2*x^2+x^11*2*x*2*x^2)}};

Related

Figlet wrap in R: How to vary width/size of cat/message output?

Can I increase the size or width of a line?
For example, the below is wrapped after the second 'a', and I'd like it all to be on one line.
#install.packages("Rfiglet")
library(Rfiglet)
figlet('starwars',
respect.linebreaks = FALSE,
smush = TRUE,
font = "starwars")
_______.___________. ___ .______ ____ __ ____ ___
/ | | / \ | _ \ \ \ / \ / / / \
| (----`---| |----` / ^ \ | |_) | \ \/ \/ / / ^ \
\ \ | | / /_\ \ | / \ / / /_\ \
.----) | | | / _____ \ | |\ \----. \ /\ / / _____ \
|_______/ |__| /__/ \__\ | _| `._____| \__/ \__/ /__/ \__\
.______ _______.
| _ \ / |
| |_) | | (----`
| / \ \
| |\ \----.----) |
| _| `._____|_______/
options(width = 999) didn't change anything.
Deciding if the text has to be printed in 1 line or 2 line is decided from figlet function internally most probably based on number of characters in the input.
figlet function returns a character vector, we can achieve what we want by using a hack. When the output is spread across 2 lines we can combine the two lines using paste and change the class back to 'figlet'.
library(Rfiglet)
tmp <- figlet('starwars',
respect.linebreaks = TRUE,
smush = FALSE,
font = "starwars")
n <- length(tmp)
tmp1 <- paste(tmp[1:(n/2)], tmp[(n/2 + 1):n])
class(tmp1) <- 'figlet'
tmp1
_______..___________. ___ .______ ____ __ ____ ___ .______ _______.
/ || | / \ | _ \ \ \ / \ / / / \ | _ \ / |
| (----``---| |----` / ^ \ | |_) | \ \/ \/ / / ^ \ | |_) | | (----`
\ \ | | / /_\ \ | / \ / / /_\ \ | / \ \
.----) | | | / _____ \ | |\ \----. \ /\ / / _____ \ | |\ \----..----) |
|_______/ |__| /__/ \__\ | _| `._____| \__/ \__/ /__/ \__\ | _| `._____||_______/

RDieHarder: calling 'dieharder' with 'file_input_raw' leads to 'Error. This cannot happen.'

I'am trying to test my RNG (written in VHDL, numbers stored in binary file) with the RDieHarder package. But when I call the dieharder() function twice (from R) this leads to
> dh <- dieharder(rng = 'file_input_raw', test = 'diehard_runs', inputfile = 'rand.bin')
# file_input_raw(): Error. This cannot happen.
[user#host ~]$
and drops me to my shell.
Setup
Die Harder Version:
$ dieharder -h
#=============================================================================#
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
#=============================================================================#
...
R Version:
$ R --version
R version 3.3.3 (2017-03-06) -- "Another Canoe"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
RDieHarder Version:
> packageVersion('RDieHarder')
[1] ‘0.1.3’
MWE
To reproduce this, we first generate an appropriate binary file with dieharder and run the die hard tests on it.
$ dieharder -o -O0 -f rand.bin -t 5000000 && dieharder -g file_input_raw -d diehard_runs -f rand.bin
#=============================================================================#
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
#=============================================================================#
rng_name | filename |rands/second|
file_input_raw| rand.bin| 4.49e+07 |
#=============================================================================#
test_name |ntup| tsamples |psamples| p-value |Assessment
#=============================================================================#
# The file file_input_raw was rewound 4 times
diehard_runs| 0| 100000| 100|0.77169947| PASSED
diehard_runs| 0| 100000| 100|0.68299332| PASSED
All tests where passed, fine. So we switch to R and do the same thing again and asume we want some more tests, like the STS Runs test.
> library('RDieHarder')
> dh <- dieharder(rng = 'file_input_raw', test = 'diehard_runs', verbose = TRUE, inputfile = 'rand.bin')
Dieharder called with gen=201 test=15 seed=2852951401
# 10000000 rands were used in this test
# The file file_input_raw was rewound 2 times
#==================================================================
# Diehard Runs Test
# This is the RUNS test. It counts runs up, and runs down,
# in a sequence of uniform [0,1) variables, obtained by float-
# ing the 32-bit integers in the specified file. This example
# shows how runs are counted: .123,.357,.789,.425,.224,.416,.95
# contains an up-run of length 3, a down-run of length 2 and an
# up-run of (at least) 2, depending on the next values. The
# covariance matrices for the runs-up and runs-down are well
# known, leading to chisquare tests for quadratic forms in the
# weak inverses of the covariance matrices. Runs are counted
# for sequences of length 10,000. This is done ten times. Then
# repeated.
#
# In Dieharder sequences of length tsamples = 100000 are used by
# default, and 100 p-values thus generated are used in a final
# KS test.
#==================================================================
# Run Details
# Random number generator tested: file_input_raw
# File rand.bin contains 5000000 rands of type.
# Samples per test pvalue = 100000 (test default is 100000)
# P-values in final KS test = 100 (test default is 100)
#==================================================================
# Histogram of p-values
##################################################################
# Counting histogram bins, binscale = 0.100000
# 20| | | | | | | | | | |
# | | | | | | | | | | |
# 18| | | | | | | | | | |
# | | | | | | | | | | |
# 16| | | | | | | | | | |
# | | | | | | | | | | |
# 14|****| | | | | | | |****| |
# |****| | | | | | | |****| |
# 12|****| |****| |****| |****| |****| |
# |****| |****| |****| |****| |****| |
# 10|****| |****| |****|****|****| |****| |
# |****| |****| |****|****|****| |****| |
# 8|****| |****|****|****|****|****|****|****| |
# |****| |****|****|****|****|****|****|****| |
# 6|****| |****|****|****|****|****|****|****|****|
# |****| |****|****|****|****|****|****|****|****|
# 4|****|****|****|****|****|****|****|****|****|****|
# |****|****|****|****|****|****|****|****|****|****|
# 2|****|****|****|****|****|****|****|****|****|****|
# |****|****|****|****|****|****|****|****|****|****|
# |--------------------------------------------------
# | 0.1| 0.2| 0.3| 0.4| 0.5| 0.6| 0.7| 0.8| 0.9| 1.0|
#==================================================================
# 10000000 rands were used in this test
# The file file_input_raw was rewound 2 times
#==================================================================
# Histogram of p-values
##################################################################
# Counting histogram bins, binscale = 0.100000
# 20| | | | | | | | | | |
# | | | | | | | | | | |
# 18| | | | | | | | | | |
# | | | | | | | | | | |
# 16| | | | | |****| | |****| |
# | | | | | |****| | |****| |
# 14| | | | | |****| | |****| |
# | | | | | |****| | |****| |
# 12| |****| | | |****| | |****| |
# | |****| | | |****| | |****| |
# 10|****|****| | |****|****| | |****| |
# |****|****| | |****|****| | |****| |
# 8|****|****|****| |****|****|****| |****|****|
# |****|****|****| |****|****|****| |****|****|
# 6|****|****|****|****|****|****|****|****|****|****|
# |****|****|****|****|****|****|****|****|****|****|
# 4|****|****|****|****|****|****|****|****|****|****|
# |****|****|****|****|****|****|****|****|****|****|
# 2|****|****|****|****|****|****|****|****|****|****|
# |****|****|****|****|****|****|****|****|****|****|
# |--------------------------------------------------
# | 0.1| 0.2| 0.3| 0.4| 0.5| 0.6| 0.7| 0.8| 0.9| 1.0|
#==================================================================
# 10000000 rands were used in this test
# The file file_input_raw was rewound 2 times
> summary(dh)
Diehard Runs Test
data: Created by RNG `file_input_raw' with seed=0, sample of size 100
p-value = 0.7717
Summary for test data
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.03151 0.23500 0.49970 0.49850 0.75030 0.94720
Stem and leaf plot for test data
The decimal point is 1 digit(s) to the left of the |
0 | 33667788889999
1 | 3399
2 | 0011333355
3 | 0022222266
4 | 222222446688
5 | 229999
6 | 0000224477778899
7 | 225555
8 | 0022446666888888
9 | 003355
NULL
One-sample Kolmogorov-Smirnov test
data: object$data
D = 0.06947, p-value = 0.6936
alternative hypothesis: two-sided
Wilcoxon signed rank test with continuity correction
data: object$data
V = 2507, p-value = 0.952
alternative hypothesis: true location is not equal to 0.5
Warning:
In ks.test(object$data, "punif", 0, 1, exact = TRUE) :
ties should not be present for the Kolmogorov-Smirnov test
> # calling dieharder() again yields an error
> dh <- dieharder(rng = 'file_input_raw', test = 'sts_runs', verbose = TRUE, inputfile = 'rand.bin')
Dieharder called with gen=201 test=101 seed=3570434269
# file_input_raw(): Error. This cannot happen.
[user#host ~]$
So if This cannot happen why does it happen?
I've removed my previous installation from dieharder (the dieharder package from the AUR) and build it from this repository, which is from the maintainer of RDieHarder. Now everything works fine.
EDIT
Switching from the package to the GitHub Repository doesn't really solve the problem. Seems like the error still occurs when the binary file needs to be rewound.
MWE
If we generate two new files
[user#host ~]$ dieharder -o -O0 -f rand_a.bin -t 10000000 && dieharder -g file_input_raw -d diehard_runs -f rand_a.bin
#=============================================================================#
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
#=============================================================================#
rng_name | filename |rands/second|
file_input_raw| rand_a.bin| 4.61e+07 |
#=============================================================================#
test_name |ntup| tsamples |psamples| p-value |Assessment
#=============================================================================#
# The file file_input_raw was rewound 1 times
diehard_runs| 0| 100000| 100|0.75253825| PASSED
diehard_runs| 0| 100000| 100|0.62883583| PASSED
[user#host ~]$ dieharder -o -O0 -f rand_b.bin -t 5000000 && dieharder -g file_input_raw -d diehard_runs -f rand_b.bin
#=============================================================================#
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
#=============================================================================#
rng_name | filename |rands/second|
file_input_raw| rand_b.bin| 4.35e+07 |
#=============================================================================#
test_name |ntup| tsamples |psamples| p-value |Assessment
#=============================================================================#
# The file file_input_raw was rewound 2 times
diehard_runs| 0| 100000| 100|0.01105242| PASSED
diehard_runs| 0| 100000| 100|0.48222156| PASSED
and run the same test with RDieHarder we get (not knowing why the second run doesn't need to be rewound)
> library('RDieHarder')
> dh <- dieharder(rng = 'file_input_raw', test = 'diehard_runs', verbose = FALSE, inputfile = 'rand_a.bin')
# The file file_input_raw was rewound 1 times
# 10000000 rands were used in this test
# The file file_input_raw was rewound 1 times
# 10000000 rands were used in this test
# The file file_input_raw was rewound 1 times
> dh <- dieharder(rng = 'file_input_raw', test = 'diehard_runs', verbose = FALSE, inputfile = 'rand_a.bin')
# 10000000 rands were used in this test
# The file file_input_raw was rewound 0 times
# 10000000 rands were used in this test
# The file file_input_raw was rewound 0 times
and with the shorter one
> library('RDieHarder')
> dh <- dieharder(rng = 'file_input_raw', test = 'diehard_runs', verbose = FALSE, inputfile = 'rand_b.bin')
# The file file_input_raw was rewound 2 times
# 10000000 rands were used in this test
# The file file_input_raw was rewound 2 times
# 10000000 rands were used in this test
# The file file_input_raw was rewound 2 times
> dh <- dieharder(rng = 'file_input_raw', test = 'diehard_runs', verbose = FALSE, inputfile = 'rand_b.bin')
# file_input_raw(): Error. This cannot happen.
[user#host ~]$
droping us back to the shell.

R apply script output in different formats for similar inputs

I'm using a double apply function to get a list of p-values for cor.test between any two columns of two tables.
hel_plist<-apply(bc, 2, function(x) { apply(otud, 2, function(y) { if (cor.test(x,y,method="spearman", exact=FALSE)$p.value<0.05){cor.test(x,y,method="spearman", exact=FALSE)$p.value}}) })
The otud data.frame is 90X11 (90rows,11 colums or to say dim(otud) 90 11) and will be used with different data.frames.
bc and hel - are both 90X2 data.frame-s - so for both I get 2*11=22 p-values out of functions
bc_plist<-apply(bc, 2, function(x) { apply(otud, 2, function(y) { if (cor.test(x,y,method="spearman", exact=FALSE)$p.value<0.05){cor.test(x,y,method="spearman", exact=FALSE)$p.value}}) })
hel_plist<-apply(hel, 2, function(x) { apply(otud, 2, function(y) { if (cor.test(x,y,method="spearman", exact=FALSE)$p.value<0.05){cor.test(x,y,method="spearman", exact=FALSE)$p.value}}) })
For bc I will have an output with dim=NULL a list of elements of otunames$bcnames$ p-value (a format that I have always got from these scripts and are happy with)
But for hel I will get and output of dim(hel) 11 2 - an 11X2 table with p-values written inside.
Shortened examples of output.
hel_plist
+--------+--------------+--------------+
| | axis1 | axis2 |
+--------+--------------+--------------+
| Otu037 | 1.126362e-18 | 0.01158251 |
| Otu005 | 3.017458e-2 | NULL |
| Otu068 | 0.00476002 | NULL |
| Otu070 | 1.27646e-15 | 5.252419e-07 |
+--------+--------------+--------------+
bc_plist
$axis1
$axis1$Otu037
[1] 1.247717e-06
$axis1$Otu005
[1] 1.990313e-05
$axis1$Otu068
[1] 5.664597e-07
Why is it like that when the input formats are all the same? (Shortened examples)
bc
+-------+-----------+-----------+
| group | axis1 | axis2 |
+-------+-----------+-----------+
| 1B041 | 0.125219 | 0.246319 |
| 1B060 | -0.022412 | -0.030227 |
| 1B197 | -0.088005 | -0.305351 |
| 1B222 | -0.119624 | -0.144123 |
| 1B227 | -0.148946 | -0.061741 |
+-------+-----------+-----------+
hel
+-------+---------------+---------------+
| group | axis1 | axis2 |
+-------+---------------+---------------+
| 1B041 | -0.0667782322 | -0.1660606406 |
| 1B060 | 0.0214470932 | -0.0611351008 |
| 1B197 | 0.1761876858 | 0.0927570627 |
| 1B222 | 0.0681058251 | 0.0549292399 |
| 1B227 | 0.0516864361 | 0.0774155225 |
| 1B235 | 0.1205676221 | 0.0181712761 |
+-------+---------------+---------------+
How could I force my scripts to always produce "flat" outputs as in the case of bc
OK different output-s are caused because of the NULL results from conditional function in bc_plist case. If I'd to modify code to replace possible NULL-s with NA-s I'd get 2d tables in any case.
So to keep things constant :
bc_nmds_plist<-apply(bc_nmds, 2, function(x) { apply(stoma_otud, 2, function(y) { if (cor.test(x,y,method="spearman", exact=FALSE)$p.value<0.05){cor.test(x,y,method="spearman", exact=FALSE)$p.value}else NA}) })
And I get a 2d tabel out for bc_nmds_plist too.
So I guess this thing can be called solved - as I now have a piece of code that produces predictable output on any correct input.
If anyone has any idea how to force the output to conform to previos bc_plist format instead I would still be interested as I do actually prefer that form:
$axis1
$axis1$Otu037
[1] 1.247717e-06
$axis1$Otu005
[1] 1.990313e-05
$axis1$Otu068
[1] 5.664597e-07

Matrix transpose in Ryacas

The transpose operator does not seem to work when used on a symbolic matrix
created using Ryacas.
> library(Ryacas)
Loading required package: XML
>
> u=Sym("u")
> v=Sym("v")
> w=Sym("w")
> DG=List(List(w-v), List(u-w), List(v-u))
> PrettyForm(DG)
[1] "Starting Yacas!"
Accepting requests from port 9734
/ \
| ( w - v ) |
| |
| ( u - w ) |
| |
| ( v - u ) |
\ /
> DGT=t(DG)
> PrettyForm(DGT)
/ \
| ( w - v ) |
| |
| ( u - w ) |
| |
| ( v - u ) |
\ /
> DG
{{w-v},{u-w},{v-u}};
> DGT
{{w-v},{u-w},{v-u}};
>
I was expecting DGT to be a 1 x 3 row vector.
Ryacas does not provide it. Try this:
t.Sym <- function(x) Sym("Transpose(", x, ")")
PrettyForm(t(DG))

Drupal business listing a-z indexing requirements

I want to render something like below in a view.
==================================================================
View: Car parts (Content type)
A | [B] | C | D | E | [F] | [G] | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
BONNET
FRONT BUMPER
FRONT BAR REINFORCEMENT
GUARD LEFT
GUARD RIGHT
==================================================================
How do you create the top A – Z index. The letters in [ ] are anchor links.
I think this discussion could help you:
https://drupal.org/node/403012

Resources