Testing equality of multivariate coefficients with linearHypothesis()
I would like to conduct a F-test (Wilks' Lambda test, ideally) to test the equality of the slope coefficients for a single independent variable on two dependent variables. Using the mtcars dataset, the...
View ArticleR replace row value when its matched to other column values
Is there a simple routine to do this in R. I would like to replace marker1, marker2 column value by its corresponding row value when the row value from marker1 and row value of marker2 is matched to...
View ArticleInverse Laplace transform in R
I am trying to do some computations using Laplace transforms in R. I used thecontinued fractions approach to compute Laplace transform of a birth-deathprocess as described in Abate 1999. But I cannot...
View ArticleHow to write summarySE function in R
I'm a new R user and want to make a line chart with std using ggplot. For this I am using the summarySE function.vrn1_summary<-summarySE(data,measurevar = "vrn1",groupvars =...
View ArticleR giving different results when data sampled prior to bootstrap
I have some R code where I am randomly sampling a data set, then running a stratified bootstrap on the result. I am converting some code from SAS, so I know approximately what the result should be. If...
View ArticleIs it possible to not display headers in the pages of an R Markdown PDF...
I have an R Markdown document that contains figures and tables that are separated and organized by headers and sub-headers. I very much like the organization that provides and like the ability to...
View ArticleHow to make a confusion matrix for a predictive model in R?
I have a dataframe. first column contains my the predictive score (range from 0 to 100, smaller values is expected to be in class A, larger values is expected to be in class B) for my model, 2nd column...
View ArticleIn tidyeval, what is the difference between !!var and !!sym(var)?
library(tidyverse)input_name <- "birth_year"input_value <- 19quo(filter(starwars, !!input_name == !!input_value)) # line 5quo(filter(starwars, !!sym(input_name) == !!input_value)) # line 6What's...
View ArticleHow can I resolve this error with gtsummary/tbl_summary?
It's been one day and all my tables have stopped loading. No matter what I do (restart R, update packages, shut down computer) I keep getting the same error message for all of my tables:Error: Problem...
View ArticleIssue with SpatVector wrapping when plotting
When plotting a SpatVector using ggplot2, if I define a projection using coord_sf(), it adds these lines that I think come from the data wrapping around the plot extent. Best way to...
View ArticleCanonical tidyverse method to update some values of a vector from a look-up...
I frequently need to recode some (not all!) values in a data frame column based on a look-up table. I'm not satisfied by the ways I know of to solve the problem. I'd like to do it in a clear, stable,...
View ArticleAvoiding overlapping labels in geom_textpath
I have created a simple line chart with ggplot2 and would like to use geom_textpath to display the labelnames in the chart. The problem is that the labels currently overlap too much. How can I change...
View ArticleK-means in R: How to visualize clusters without using "fviz_cluster" function...
I am trying to write code in R that uses K-means clustering after preprocessing the data using PCA. I found the "fviz_cluster" function but it seems like the function uses the first two principal...
View Articler Error dim(X) must have a positive length?
I want to compute the mean of "Population" of built-in matrix state.x77. The codes are :apply(state.x77[,"Population"],2,FUN=mean)#Error in apply(state.x77[, "Population"], 2, FUN = mean) : # dim(X)...
View ArticleHow to convert int to double when using arrow to read in multiple CSVs with...
I'm trying to convert a large folder of CSVs to parquet. The dataset it too large to fit into memory, so I'm using arrow.For some columns, some files have only whole numbers, and others have...
View ArticleModelsummary Plot: color sigfinicant with several models
with the liberary(modelsummary) I try to plot (modelplot) several models. From the vingettehttps://modelsummary.com/vignettes/modelplot.html I can see, that if I want to color according to sgfnifican...
View ArticleDisplay category with zero categories in barplot [duplicate]
Here is my code:group_composition <- turtle_data %>% group_by(group) %>% summarise( n_turtles = n(), n_male = sum(sex == "Male"), n_female = sum(sex == "Female"), n_juvenile = sum(sex ==...
View ArticleError uploading file to CIBERSORTx: unexpected end of data at line 1 column 1...
I'm trying to generate a signature file in CIBERSORTx, that can be generated by creating a Seurat object. For the CIBERSORTx link, the example data is only accessible after you sing up with them, so I...
View ArticleKey-value mapping of axis/variable labels in ggplot
I often work with dataframes with "R-friendly"/"programmer-friendly" column names, typically with no spaces, and/or abbreviated (lazy to type the full names when doing the analysis). For example:ir...
View Articlereplace magrittr operator pipe (%>%) with "+" in ggplot call
I am trying to modify this excellent answer which automatically labels ggplot objects so that it is more flexible and follows ggplot syntax (so uses +) so I can just add a call to the end of a ggplot...
View ArticleCopying code into R?
This is a very basic and stupid question, but I just haven't been able to phrase it correctly into Google to get an answer.I'm going through a book to learn R, and there are often code samples that I'd...
View ArticleIntegrating R functions in Python AWS Bedrock agents
I have the following Python code and I was just curious how I can use the rpy2 package to import some R functions such that Bedrocks Agent() can have access to them. (I know I could just write a...
View ArticleVignette creation on package build fails with the error "Failed to locate the...
I've written an R package, which lives here and contains a vignette intended to step users through the rationale behind the package and how to best use it.Unfortunately, on an attempt to build a source...
View ArticleHow to get estimated expected values in glmmTMB?
Is there a way to obtain estimated expected values from a glmmTMB object? Specifically, if Y is the response vector and X,Z are design matrices for fixed and random effects respectively, I want an...
View ArticleHow can i fix the Position_stack function that does not work in R?
I am using ggplot2 to create a horizontal bar chart. I use position_stack() function from the ggplot2 library version 4.0.0 on a Windows 11 computer.packageVersion("ggplot2")[1] ‘4.0.0’The problem is...
View ArticleHow to fix ggsankeyfier misaligned nodes and flows when facetting
I am trying to generate a sankey diagram using the ggsankeyfier package. The problem I have is that the nodes and flows are misalgined when using multiple facets as you can see in the picture. Does...
View ArticleReplace values in multiple columns in a data frame based on conditions in...
I'm working with a data frame where the color of an object (red or green) was recorded in ordinal classes corresponding to percent coverage.I am looking to replace all the classes with their...
View ArticleCropped polygon sf not filling plot area after being projected
I am running code that I previously used to create maps for my data. The background for the map is:library(rnaturalearth)library(sf)countries <- ne_countries(scale = "medium", returnclass = "sf")...
View ArticleIntersecting very large shape files with thousands of multi-polygons
I have several multi-polygons shape files (the data is here https://habitats.oceanplus.org/, I don't have a way to provide direct downloads).These shapefiles are anywhere between 200Mb to 1Gb and they...
View ArticleR: Number of classes is not equal to 2
I am getting the following error when trying to generate a lift chart for a random forest model being run through rattle:Error in prediction(crs$pr, no.miss) : Number of classes is not equal to 2.ROCR...
View Article