How to write strings in Math Equations in Jupyter Notebook - jupyter-notebook

I want to write the next equation (only the first part)
in a Jupyter notebook.
When I tried with this code
\begin{gather*}
Sensitivity = \frac{number true positives}{number of true positivities + number of false negatives}
\end{gather*}
I get this:

This is how you can embed text in LaTeX:
\text{Some text with spaces}
So in your case, it could look like this:
\begin{gather*}
Sensitivity = \frac{\text{number true positives}}{\text{number of true positivities} + \text{number of false negatives}}
\end{gather*}

Related

R iterations only saving the first value of a vector

Up until now I find any problem I have has been had and posted here already, but this time I'm really at a loss.
I am running grep in R to look for a list of regex values in two strings, and write the ones that are exclusive to one string and not the other. The outputs are vectors, but when I loop through the vectors or even just try to save them, R is only saving the first value of the vector.
So while:
inWT = as.list(rep(0, nrow(NEBres)))
> c(setdiff(c(grep(NEBres$Recognition_Site[1], reverseComplement(bigfile$FASTA, case = "upper")),
grep(NEBres$Recognition_Site[1], bigfile$FASTA)),
c(grep(NEBres$Recognition_Site[1], reverseComplement(bigfile$m_FASTA, case = "upper")),
grep(NEBres$Recognition_Site[1], bigfile$m_FASTA))))
>[1] 86 480
if I try to save it it only saves the first value as so:
inWT[1] = c(setdiff(c(grep(NEBres$Recognition_Site[1], reverseComplement(bigfile$FASTA, case = "upper")),
grep(NEBres$Recognition_Site[1], bigfile$FASTA)),
c(grep(NEBres$Recognition_Site[1], reverseComplement(bigfile$m_FASTA, case = "upper")),
grep(NEBres$Recognition_Site[1], bigfile$m_FASTA))))
> inWT[1]
[[1]]
[1] 86
I haven't been able to manage this solution for some time now, and I'm starting to run out of solutions.
Thanks in advance!

R Sweave: digits number in xtable of prop.table

I'm making an xtableFtable on R Sweave and can't find a way to suppress the digits with this code. What I am doing false? I've read that it can happen if your values aren't numeric but factor or character, but is prop.table making them non-numeric? I'm lost...
library(xtable)
a <- ftable(prop.table(table(mtcars$mpg, mtcars$hp), margin=2)*100)
b <- xtableFtable(a, method = "compact", digits = 0)
print.xtableFtable(b, rotate.colnames = TRUE)
I've already tried with digits=c(0,0,0,0...) too.
You could use options(digits) to control how many digits will print. Try something like options(digits = 4) as the first line of your code (change 4 to whatever value you want between 1 and 22). See ?options for more information.
Or round the values before printing
a = round(ftable(prop.table(table(mtcars$mpg, mtcars$hp), margin=2)*100), 2)
b = xtableFtable(a, method = "compact")
print.xtableFtable(b, rotate.colnames = TRUE)
The "digits" argument to xtableFtable seems to be unimplemented (as of my version, which is 1.8.3), since after playing around with it for half an hour nothing seems to make any difference.
There's a hint to this effect in the function documentation:
It is not recommended that users change the values of align, digits or align. First of all, alternative values have not been tested. Secondly, it is most likely that to determine appropriate values for these arguments, users will have to investigate the code for xtableFtable and/or print.xtableFtable.
It's probably just carried over from the xtable function (on which xtableFtable is surely based) as a TODO which the maintainer hasn't gotten around to yet.

How to diplay subscripts and array elements simultaneously on r plot

I have a coefficient array bees created in the following way:
gfit = lm(y_data,x_data);
bees = coef(gfit);, where bees[1]=0.123, bees[2]=4.56
A plot plot(x_data,y_data) is created. I'd liket to add some text on this plot. The text should look like $b_0=0.123, b_1=4.55$ (how to add Latex symbols on StackOverflow?).
I tried the following command: text(3,15,expression(paste("b"[0],"="bees[1])));, which turns out to be $b_0=bees_1$, i.e. the variable bees[1] is not interpreted properly.
How can I display the value of a variable by typing its name?
R doesn't have a LaTeX interpreter. You need to use ?plotmath. Try using bquote to allow getting values of R-objects , and here assuming that (1,1) is in the range of your (undescribed) data. The .()-function will put values pulled from the working environment into expressions:
text(1,1, bquote( list( b[0] == .(bees[1]) , b[1] == .(bees[2]) ) ) )
See the examples in ?bquote.
Writing formulas is a horrible mess in R. Only regexp is more write-only.
bees=c(0.12, 4.56)
plot(rnorm(100))
text(30,0,bquote(bees[1]== .(bees[1])))

GNUPlot: Plot each data block on new graph ("for each datablock")

I have a file which I am plotting with gnuplot. My data looks like this:
x,y1,y2
0,0,0
1,0.0,0.1
1,0.1,0.15
1,0.3,0.2
... etc
2 blank lines -> new block
0,0,0
0,0,0 (just example data)
0,0,0
... etc
2 blank lines -> new block
0,0,0
0,0,0
0,0,0
... etc
... etc (more blocks)
If I run the command: plot 'file.csv' using 1:2, then all the blocks appear on the same graph. I have about 1000 blocks, so obviously this produces something unreadable.
How can I plot all the blocks on different graphs? Sort of like a "for each datablock" loop or something?
Possible Partial Answer
I have made progress on this using a gnuplot for loop. This might not actually be a particularly good method, and I am now stuck as I am unable to count the number of "data blocks" in my file.
This is what I have so far:
NMAX=3 # How do I know what this should be?
do for [n=0:NMAX] {
ofname=sprintf("%d.png", n)
set output ofname
plot 'timeseries.csv' index n using 1:2, 'timeseries.csv' index n using 1:3 with lines
}
Perhaps that is useful? At the moment I don't know how to set NMAX automatically.
Further Developments
NMAX can be set using the stats command: stats 'datafile.csv' then NMAX=STATS_blocks.
There may be a better method.
This question helped me: Count number of blocks in datafile
My code:
stats datafile
NMAX=STATS_blocks
do for [n=0:NMAX] {
ofname=sprintf("%d.png", n)
set output ofname
plot 'timeseries.csv' index n using 1:2, 'timeseries.csv' index n using 1:3 with lines
}

R linear model can't process values of 0

I can't seem to get the lm function to work properly on any columns that have 0 as a data value. Here is my code:
project.lm = lm(SalePrice ~Lot.Area + Year.Built + Year.Remod.Add + Gr.Liv.Area +
Yr.Sold + Bsmt.Unf.SF, project.table)
But when I do summary of project.lm, I get literally thousands of variables in my linear model, in fact one variable for each value of Bsmt.Unf.SF. This occurs for all columns where there is a value of 0; otherwise, everything works fine. Any ideas?!?
See the documentation for read.csv and read.table : there's an argument called stringsAsFactors which is TRUE by default. Set it to FALSE and you may be happier :-)

Resources