I have a spatial dataframe (sf) of all European NUTS2 regions. Within this sf object certain regions have a dummy = 1, and others a dummy = 0.
How can I create a new dummy (lets say "dummy_neighbor") where all the neighboring (st_touches?) regions of the regions with dummy==1 get a dummy_neighbor==1, and all those not touching a dummy==1 region get a dummy_neighbor==0?
For the time being I have this work-around. But I guess there musst be an easier solution?
# load packages
library(sf)
library(here)
library(tidyverse)
library(spdep)
library(expp)
# import nuts 2 sf object
nuts2_sf <- st_read(here("Data", "nuts2_data", "final_nuts.shp"))
# take row numbers as extra column for later
nuts2_sf$rownumber = 1:nrow(nuts2_sf)
#neighbouring list
neighbour <- poly2nb(nuts2_sf, row.names="NUTS_ID", queen=TRUE)
# transform nb into data frame
nb_df <- plyr::ldply(neighbour, rbind)
nb_df$rownumber = 1:nrow(nb_df) # get rownbumer as column
# merge neighbour-list-df with sf by rownumber
df <- merge(nuts2_sf, nb_df, by = "rownumber")
# extract all neighbours of tp100_d=1
# (tp100_d is the name of the original dummy variable)
df_dummy <- df %>% filter(tp100_d == 1)
df_dummy$geometry <- NULL
all_neighbours <- as.vector(as.matrix(df_dummy[,c(66:76)])) %>% unique(.)
# create new neighbourhood-dummy for all neighbours (but not if its a neighbour that has a 1 in its original dummy)
nuts2_sf <- nuts2_sf %>% mutate(nb_dummy = ifelse(rownumber %in% all_neighbours & tp100_d == 0, 1, 0))
I'm using gtsummary package.
I need to merge different univariate logistic regression and in order to have a good presentation, I want to hide the p_value and bold or put a star to the significant OR (p< 0.05).
Anyone can help me?
Maybe it's easier to use another presentation type like kable, huxtable, I don't know?
Thank you for your help.
Have a nice day
There is a function called add_significance_stars() that hides the p-value and adds stars to the estimate indicating various levels of statistical significance. I've also added code to bold the estimate if significant with modify_table_styling().
library(gtsummary)
#> #BlackLivesMatter
packageVersion("gtsummary")
#> [1] '1.4.0'
tbl <-
trial %>%
select(death, age, grade) %>%
tbl_uvregression(
y = death,
method = glm,
method.args = list(family = binomial),
exponentiate = TRUE
) %>%
# add significance stars to sig estimates
add_significance_stars() %>%
# additioanlly bolding significant estimates
modify_table_styling(
columns = estimate,
rows = p.value < 0.05,
text_format = "bold"
)
Created on 2021-04-14 by the reprex package (v2.0.0)
Here's a quick huxtable version:
l1 <- glm(I(cyl==8) ~ gear, data = mtcars, family = binomial)
l2 <- glm(I(cyl==8) ~ carb, data = mtcars, family = binomial)
huxtable::huxreg(l1, l2, statistics = "nobs", bold_signif = 0.05)
────────────────────────────────────────────────────
(1) (2)
───────────────────────────────────
(Intercept) 5.999 * -1.880 *
(2.465) (0.902)
gear -1.736 *
(0.693)
carb 0.579 *
(0.293)
───────────────────────────────────
nobs 32 32
────────────────────────────────────────────────────
*** p < 0.001; ** p < 0.01; * p < 0.05.
Column names: names, model1, model2
It doesn't show it here, but the significant coefficients are bold on screen (and in any other kind of output).
I would like to call a single value from a table inside a textbody.
% latex table generated in R 3.5.1 by xtable 1.8-3 package
% Wed Dec 12 13:56:07 2018
\begin{table}[ht]
\centering
\begin{tabular}{rrrrr}
\hline
& Estimate & Std. Error & z value & Pr($>$$|$z$|$) \\
\hline
(Intercept) & -1.819 & 0.926 & -1.964 & 0.050 \\
hiveH2 & 2.418 & 0.951 & 2.542 & 0.011 \\
nectar+ & 0.827 & 0.947 & 0.873 & 0.383 \\
\hline
\end{tabular}
\label{tab:x}
\end{table}
I would like to be able to write something along the line:
The z value of Hive~2 is \call{tab:x{z value}{hiveH2}}.
That should compile as:
The z value of Hive 2 is 2.542.
the LaTeX table was generated with a R script (neither R markdown nor R sweave):
library(lme4)
library(xtable)
data <- matrix(c("H1","H1","H2","H2","H1","H1","H2","H2","H1","H1","H2","H2","H1","H1","H2","H2","H1","H1","H2","H2","H1","H1","H2","H2","H1","H1","H2","H2",
"+","+","-","-","+","+","-","-","+","+","-","-","+","+","-","-","-","-","+","+","-","-","+","+","-","-","+","+",
0.00000000,0.00000000,0.25000000,0.00000000,0.00000000,0.00000000,0.00000000,0.10000000,0.20000000,0.00000000,0.10000000,0.00000000,0.00000000,0.00000000,0.00000000,0.09090909,0.09090909,0.00000000,0.41666667,0.08333333,0.00000000,0.14285714,0.85714286,0.61538462,0.00000000,0.00000000,0.25000000,1.10000000),
nrow=28, ncol=3)
data <- as.data.frame(data)
colnames(data) <- c("hive", "nectar", "severity")
glm <- glm(severity ~ hive + nectar, data = data, family = binomial)
summary.glm <- summary(glm)
summary.glm
print(xtable(summary.glm, type = "latex", caption.placement = getOption("xtable.caption.placement", "bottom"),
digits = 3,
label = "tab:x",
table.placement = getOption("xtable.table.placement", "h")),
file = "test.tex")
Based on info from this source - http://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics.
I tried to have 3 columns in equation:
<math>
\begin{align}
f(x) & = h(&x, y)\\
& = G(&x, y,\\
& &z)
\end{align}
</math>
to have x and z aligned, but it is not aligned...
I'm rying with wikipedia sandbox.
You should use an array to properly achieve multiple alignment points. Also, some spacing adjustments (\! is a negative math space) make the display look better:
<math>
\begin{array}{rll}
f(x) &\!\!\! = h(&\!\!\!\! x, y) \\
&\!\!\! = G(&\!\!\!\! x, y, \\
&\!\!\! &\!\!\!\! z)
\end{array}
</math>
I want to left align a block of equations. The equations in the block itself are aligned, but that's not related at all to my question! I want to left align the equations rather than have them centered all the time, because it looks dumb with narrow centered equations.
Example, I want to left align this
\begin{align*}
|\vec a| &= \sqrt{3^{2}+1^{2}} = \sqrt{10} \\
|\vec b| &= \sqrt{1^{2}+23^{2}} = \sqrt{530} \\
\cos v &= \frac{26}{\sqrt{10} \cdot \sqrt{530}} \\
v &= \cos^{-1} \left(\frac{26}{\sqrt{10} \cdot \sqrt{530}}\right) \\
v &= \uuline{69.08...\degree}
\end{align*}
but also this
\begin{align*}
f(x) = -1.25x^{2} + 1.5x
\end{align*}
How is this done? If it's even possible.
Try to use the fleqn document class option.
\documentclass[fleqn]{article}
(See also http://en.wikibooks.org/wiki/LaTeX/Basics for a list of other options.)
You can use \begin{flalign}, like the example bellow:
\begin{flalign}
&f(x) = -1.25x^{2} + 1.5x&
\end{flalign}
Try this:
\begin{flalign*}
&|\vec a| = \sqrt{3^{2}+1^{2}} = \sqrt{10} & \\
&|\vec b| = \sqrt{1^{2}+23^{2}} = \sqrt{530} &\\
&\cos v = \frac{26}{\sqrt{10} \cdot \sqrt{530}} &\\
&v = \cos^{-1} \left(\frac{26}{\sqrt{10} \cdot \sqrt{530}}\right) &\\
\end{flalign*}
The & sign separates two columns, so an & at the beginning of a line means that the line starts with a blank column.
The fleqn option in the document class will apply left aligning setting in all equations of the document. You can instead use \begin{flalign}. This will align only the desired equations.