logo
down
shadow

Change row names of a table obtained from a lm regression using xtable function


Change row names of a table obtained from a lm regression using xtable function

Content Index :

Change row names of a table obtained from a lm regression using xtable function
Tag : r , By : Asbie
Date : November 25 2020, 07:22 PM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Adding custom row(s) to an LaTeX-outputted R table of regression results using memisc, xtable etc.


Tag : r , By : user90210
Date : March 29 2020, 07:55 AM
it fixes the issue You might try to add that new line(s) directly to the table you want to pass to e.g. xtable. Really lame example:
m <- lm(mtcars$hp ~ mtcars$wt)
df <- as.data.frame(summary(m)$coefficient)
df[3, ] <- c(sample(c('foo', 'bar'), 4, replace = TRUE))
rownames(df)[3] <- 'FOOBAR'
> df
                     Estimate       Std. Error             t value            Pr(>|t|)
(Intercept) -1.82092177119464 32.3246158121787 -0.0563323561763288     0.95545056134944
mtcars$wt    46.1600502824445 9.62530003926982    4.79569988406785 4.14582744107531e-05
FOOBAR                    bar              foo                 bar                  bar
> xtable(df)
% latex table generated in R 2.15.0 by xtable 1.7-0 package
% Tue Jun 12 01:39:46 2012
\begin{table}[ht]
\begin{center}
\begin{tabular}{rllll}
  \hline
 & Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\ 
  \hline
(Intercept) & -1.82092177119464 & 32.3246158121787 & -0.0563323561763288 & 0.95545056134944 \\ 
  mtcars\$wt & 46.1600502824445 & 9.62530003926982 & 4.79569988406785 & 4.14582744107531e-05 \\ 
  FOOBAR & bar & foo & bar & bar \\ 
   \hline
\end{tabular}
\end{center}
\end{table}

sql, matching row values obtained from first table to the column names of second table without loop


Tag : python , By : user187301
Date : March 29 2020, 07:55 AM
this will help You don't need to re-query the second table over and over again, you could just retrieve the one row once and use that as a lookup-table. If you use the sqlite3.Row row factory that is as easy as retrieving one row:
memcon.row_factory = sqlite3.Row
memdata.execute("select * from tabletwo where tabletwo.Gene_ID == 'NFYA'")
nfya_row = memdata.fetchone()

memdata.execute("SELECT tableone.SampleID from tableone WHERE tableone.Diagnos=='RH'")
for row in memdata:
    sampleID = row['SampleID']
    print sampleID, nfya_row[sampleID]
memdata.execute("select * from tabletwo where tabletwo.Gene_ID == 'NFYA'")
nfya_row = {desc[0]: column for desc, column in zip(memdata.getdescription(), memdata.next())}

memdata.execute("SELECT tableone.SampleID from tableone WHERE tableone.Diagnos=='RH'")
for row in memdata:
    sampleID = row[0]
    print sampleID, nfya_row[sampleID]

xtable for MANOVA object obtained with car package


Tag : r , By : Thomas Plunkett
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The problem is that xtable has a method for objects of class anova, but the car package's Anova function returns an object of class anova.mlm. I found a fix at https://stat.ethz.ch/pipermail/r-help/2009-June/201478.html:
library(xtable)
library(car)

# Create some example data
Pottery <- data.frame(
  "Al" = rnorm(10),
  "Fe" = rnorm(10),
  "Mg" = rnorm(10),
  "Ca" = rnorm(10),
  "Na" = rnorm(10),
  "Site" = sample(LETTERS[1:2], 10, replace = TRUE))

# Create a custom function handling `anova.mlm` objects
xtable.Anova.mlm <- function (x, ...) {
  test <- x$test
  repeated <- x$repeated
  ntests <- length(x$terms)
  tests <- matrix(NA, ntests, 4)
  if (!repeated)
    SSPE.qr <- qr(x$SSPE)
  for (term in 1:ntests) {
    eigs <- Re(eigen(qr.coef(if (repeated) qr(x$SSPE[[term]]) else
      SSPE.qr,
      x$SSP[[term]]), symmetric = FALSE)$values)
    tests[term, 1:4] <- switch(test, Pillai = stats:::Pillai(eigs,
      x$df[term], x$error.df), Wilks = stats:::Wilks(eigs,
        x$df[term], x$error.df), `Hotelling-Lawley` = stats:::HL(eigs,
          x$df[term], x$error.df), Roy = stats:::Roy(eigs,
            x$df[term], x$error.df))
  }
  ok <- tests[, 2] >= 0 & tests[, 3] > 0 & tests[, 4] > 0
  ok <- !is.na(ok) & ok
  tests <- cbind(x$df, tests, pf(tests[ok, 2], tests[ok, 3],
    tests[ok, 4], lower.tail = FALSE))
  rownames(tests) <- x$terms
  colnames(tests) <- c("Df", "test stat", "approx F", "num Df",
    "den Df", "Pr(>F)")
  tests <- structure(as.data.frame(tests), heading = paste("\nType ",
    x$type, if (repeated)
      " Repeated Measures", " MANOVA Tests: ", test, " test
statistic",
    sep = ""), class = c("anova", "data.frame"))
  #    print(tests)
  #    invisible(x)
  xtable(tests)
}


MANOVA <- Anova(lm(cbind(Al, Fe, Mg, Ca, Na) ~ Site, data=Pottery))

xtable(MANOVA)

% latex table generated in R 2.15.2 by xtable 1.7-1 package
% Tue Jun 11 20:49:51 2013
\begin{table}[ht]
\centering
\begin{tabular}{lrrrrrr}
\hline
& Df & test stat & approx F & num Df & den Df & Pr($>$F) \\ 
\hline
Site & 1 & 0.61 & 1.24 & 5 & 4 & 0.4288 \\ 
\hline
\end{tabular}
\end{table}

knitr, R Markdown, and xtable: xtable tables within HTML table


Tag : html , By : Jason Vance
Date : March 29 2020, 07:55 AM
this will help I think your code will work if you put results=asis in the chunk options.
<table border = 1>
<tr>
<td>
```{r results='asis', echo=FALSE}
  library(xtable)
  data(tli)
  print(xtable(tli[1:20, ]),type='html')
```
</td>
<td>
```{r results='asis', echo=FALSE}
  library(xtable)
  data(tli)
  print(xtable(tli[1:20, ]),type='html',comment=FALSE)
```
</td>
</tr>
</table>

How to set spaces in the column names of a table or data frame using xtable


Tag : r , By : Mr. Tacos
Date : March 29 2020, 07:55 AM
To fix this issue So I want to use spaces among words in the names of the columns of a data frame and print the data frame to a pdf in latex format. However, when I use xtable() to do this, the names of the columns get joined. , Your best bet is probably to use the sanitize.* options, e.g.:
> print.xtable(xtable(dat),include.rownames=F,
               sanitize.colnames.function=function(x)gsub("\\."," ",x))

% latex table generated in R 3.2.1 by xtable 1.7-4 package
% Thu Aug 20 10:47:54 2015
\begin{table}[ht]
\centering
\begin{tabular}{llll}
  \hline
Variable & Categoría de Referencia & Categoría Considerada & Variación \\ 
  \hline
Uso & No Acaba Unidad & Acaba la Unidad & 2.08\% \\ 
  País & Brasil & España & 0.31\% \\ 
  País & Brasil & Francia & 0.46\% \\ 
  País & Brasil & ITalia & 0.7\% \\ 
  País & Brasil & Méjico & -0.19\% \\ 
  País & Brasil & Otros Países & -0.46\% \\ 
  Clicker & Clicker & No Cliker & -2.32\% \\ 
  App & No Usa App & Usa App & 1.15\% \\ 
   \hline
\end{tabular}
\end{table}
datmat<-as.matrix(dat)
colnames(datmat)<-c("Variable","Categoría de Referencia",
                    "Categoría Considerada", "Variación")
print.xtable(xtable(datmat),include.rownames=F)
Related Posts Related QUESTIONS :
  • R - building new variables from sequenced data
  • Sum rows values one after the other
  • Nesting ifelse inside summarytools
  • How best to divide different levels of a factor by one another in dataframe in R?
  • Why does my code run multiple times before I type data into the table? How do I make an action button that creates a tab
  • How to impute missing values not at random?
  • Set the y limits of an added average line of a plotly plot
  • how to calculate a new column after grouping with dplyr
  • Extract data from rows creating new columns using R
  • Create a filled area line plot with plotly
  • When do I need parentheses around an if statement to control the sequence of a formula in R?
  • my graph in ggplot2 contains an "e" character in y-axis
  • Making variables immutable in R
  • R: Difference between the subsequent ranks of a item group by date
  • Match data within multiple time-frames with dplyr
  • Conditional manipulation and extension of rows in data.table also considering previous extensions without for-loop
  • Conditional formula referring to preview row in DF not working
  • Set hoverinfo text in plotly scatterplot
  • Histogram of Sums from Categorical/Binary Data
  • Efficiently find set differences and generate random sample
  • Find closest points from data set B to point in data set A, using lat long in R
  • dplyr join on column A OR column B
  • Replace all string if row starts with (within a column)
  • Is there a possibility to combine position_stack and nudge_x in a stacked bar chart in ggplot2?
  • How can I extract bounding boxes in a row-wise manner using R?
  • How do I easily sum up values in different columns?
  • Reading numeric Date value from CSV file to data.frame in "R"
  • R programming: creating a stacked bar graph, with variable colors for each stacked bar
  • How to identify all columns that contain binary representation
  • Filter different groups by different factor levels
  • Saving .xlsx file to disc, form http post request
  • Add an "all" option under the filter that selects the number of rows displayed in a datatable
  • How to select second column of every xts in list
  • Generate a frequency dataframe out of an input dataframe
  • Why manual autocorrelation does not match acf() results?
  • Merge 3 dataframes which are different to each other
  • remove adjacent duplicates from string
  • How to change the position of stacked stacked bar chart in ggplot in R?
  • How to divide each of a range a variables by a second range of variables in R
  • Why do I need to assemble vector before scaling in Spark?
  • How to select individuals which appear in multiple groups?
  • How can I fill columns based on values in another column?
  • 32 bit R and 64 bit R: output differs
  • Remove a single backslash in paste0 output
  • ggplot2 different label for the first break
  • TSP in R, with given distances
  • How to find the given value from the range of values?
  • Solution on R group by issue _ multiple combination
  • Transform multiple columns with a function that uses different arguments per column
  • How can I parse a string with the format "1/16/2019 1:24:51" into a POSIXct or other date variable?
  • How to plot a box plot in R for outlier detection for a huge number of rows?
  • How to change column name according to another dataframe in R?
  • `sjPlot::tab_df()`--how to set the number of decimal places?
  • time average for specific time range in r
  • joining dataframes by closest time and another key in r
  • How to create nested for loop for a certain range
  • New category based on sequence of date ranges
  • how to extract formula from coxph model summary in R?
  • add row based on variable condition in R
  • Generating the sequence 111122222333334
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com