Posts by fsbmat • 1,291 points
54 posts
-
2
votes2
answers55
viewsA: Label of data overlapping
Use the package ggrepel and the function geom_text_repel library(ggrepel) dt <- data.frame(periodo = c("JUN", "JUL","AGO","SET","OUT","NOV","DEZ"), diam =…
-
4
votes1
answer30
viewsQ: Error while integrating a real function
I’m trying to integrate, under the whole line, the function: integrand_1<-function(x){ exp(-x/phi-y*exp(-x)/(phi*2)-(x+sigma2/2)^2/(2*sigma2))} Using the following data: df <-…
-
3
votes1
answer62
viewsA: There are ways to add figures on a Plot in R
I managed to make the figure also in ggplotly, using the code below: plot <- tres %>% ggplot(aes(Time, Pontos, fill=Time, text=paste("Time:", Time, "<br>", "Pontuação: ", Pontos)))+…
-
5
votes1
answer62
viewsQ: There are ways to add figures on a Plot in R
Gero this figure: when using that code: library(tidyverse) library(plotly) tres <- readRDS(…
-
1
votes1
answer200
viewsA: Write.csv and write.xlsx problems
Apparently it was the antivirus Avast that was causing the problem. I disabled it for 10 min and reinstalled the xlsx package. I rebooted the R and after 24 hours lost, I was able to make it work…
-
0
votes1
answer200
viewsQ: Write.csv and write.xlsx problems
I use windows 64 bits, I have java installed and set the working directory in R. But, when running a simple code such as: teste <- data.frame(a=c(2,2),b=c(3,3)) write.csv2(teste,file =…
-
1
votes1
answer593
viewsA: How to edit the variables name in a ggplot without having to change the table data?
I imagine that’s what you’re looking for: ggplot(myc_t, aes(x=Receiver, y=Transmitter))+ geom_point() + xlab("ID dos receptores") + ylab("ID dos tags") + scale_x_discrete(labels = c("#R01", "#R02"))…
-
1
votes1
answer170
viewsQ: Aggregating values in R
When trying to add values per person, I get the error below saying that the function sumdoes not work for factors, however, my vector is numerical and even using a function to ensure this, I…
-
2
votes1
answer89
viewsQ: Removing lines from a problematic database in R
A few days ago I asked a question in the stack, according to link. The reply I received from prof. @Marcus Nunes shows that less than 10% of lines have more than 15 tabs of the type ;. In that case,…
-
1
votes2
answers317
viewsQ: Read error with the fread function of the data.table package
By downloading the database of values of daily and tickets 2019 the portal of transparency http://www.portaltransparencia.gov.br/download-de-dados/viagens, I used the code below to read the daily…
-
3
votes1
answer545
viewsQ: Create new column from existing column in R
I have a database in which the first column has the code of the disciplines of my institution and the second column has the name of the respective discipline. I want to create a third column where…
-
3
votes2
answers290
viewsQ: Create a bar graph in ggplot2 with juxtaposed columns
I would like to create a bar chart on ggplot2 with x1 and x2 side by side comparing month to month. I tried the following code, but was unsuccessful: Mean_2013 <-…
-
4
votes2
answers88
viewsQ: Create a column with the second highest row value
I would like to create a column on dataframe teste with the second highest value of the respective line, as I did to find Min and Max. library("matrixStats") teste <-…
-
2
votes1
answer177
viewsQ: Error in the application of the Boxcox function of the MASS package
I’m getting the following error while using the function boxcox() package MASS: Error in as.data.frame.default(data, optional = TRUE) : cannot coerce class ‘"function"’ to a data.frame I don’t…
-
0
votes1
answer53
viewsA: Aggregating data with different dates and considering other columns in R
Apparently I got a solution, maybe not the fastest due to the loop, but the important thing is that it worked. Follow the code:…
-
0
votes1
answer53
viewsQ: Aggregating data with different dates and considering other columns in R
I would like to aggregate the lines of dataframe TBCG2, when the DATA_INGRESSO_ORGAO is different (see column ID_SERVIDOR_PORTAL numbers 977, 1089, 1365, 1666, 2597, 2779 and 3036). I want to keep…
-
4
votes1
answer90
views -
2
votes0
answers384
viewsQ: Doubts about discriminant analysis in R
I’m trying to reproduce the accounts of example 5 of this pdf about discriminant analysis. When doing the accounts without using any package, get the same results of the file, as code below.…
-
2
votes1
answer93
viewsA: How to change the distance or rotation of the axis heading of a graph relative to the axis itself
The code below solved my problem by putting the label of the z axis horizontally: par(mar = c(5.1, 9.1, 4.1, 2.1)) pmat <- persp3D(t1, t2, z, main="", xlab="$y_{1}$", ylab="$y_{2}$", zlab="",…
-
5
votes1
answer93
viewsQ: How to change the distance or rotation of the axis heading of a graph relative to the axis itself
I make the graphic below using the plot3D package of R. I would like to move the label a little away from the z axis ($f(y_{1},y_{2})$) of the values of the axis or leave it horizontal. Does anyone…
-
1
votes0
answers267
viewsQ: Generate random numbers in R with Skew-Normal Bivariate distribution
I did the script below, but I doubt if it is correct, I need to generate a bivariate vector with medium skew-normal distribution mu=(mu1,mu2), matrix of variance and covariance…
-
4
votes2
answers158
viewsQ: Play a chart in R
I made graph 1 below in R, from the code: library(truncreg) set.seed(1) x <- sort(rnorm(50)+3) y <- 3 + 1*x + rnorm(50,0,0.3) compl <- data.frame(x,y) y[y>6.5] <- 6.5 sample <-…
-
2
votes1
answer1256
viewsA: Play 3d graph with level curves in R software
I managed to solve: source("https://raw.githubusercontent.com/walmes/wzRfun/master/R/panel.3d.contour.R") library(lattice) library(manipulate) library(colorRamps) #Function density probability…
-
1
votes1
answer1256
viewsQ: Play 3d graph with level curves in R software
I tried to add level curves in my Plot as in the second figure below, but I could not, someone knows how I should proceed? #Function density probability library(pbivnorm) bsb <- function(t1,t2){…
-
2
votes2
answers273
viewsA: Play ggplot2 graph using multiple facets
I was able to do it using the grid.: library(ggplot2) library(grid) library(utils) grid.newpage() #Lendo os dados dt1 <- read.table("https://cdn.rawgit.com/fsbmat/StackOverflow/master/sim50.txt",…
-
0
votes2
answers273
viewsQ: Play ggplot2 graph using multiple facets
I built the chart below using the command grid.arrange package gridExtra, I would like to leave you with the look of the graphics made with multiple facets, using the sample size as facet, is…
-
4
votes1
answer256
viewsQ: How to play a graph that was created with the Plot command using ggplot2?
How to play the chart below using the ggplot2? I don’t know how to add the various charts into one layer single! bs<-function(t,mu,phi){…
-
1
votes2
answers1312
viewsA: How to change the "Key" orientation of a Caption in ggplot?
I managed to resolve the issue in the stack in English, follows the solution: set.seed(000) m <- matrix(rnorm(100,0,1),100,1) dt <- data.frame(m) names(dt) <- c("X") library(ggplot2) g2…
-
4
votes2
answers1312
viewsQ: How to change the "Key" orientation of a Caption in ggplot?
how can I change the "key" of the caption below, so that it stays in the horizontal position, without changing the vertical lines of the chart. Also, how to leave the caption background with the…
-
2
votes2
answers1175
viewsQ: Find a particular line or specific value of a matrix vector in R
How to build a function that evaluates if any row of the matrix mat is equal to the vector vec both in the code below: set.seed(000) mat <- matrix(rnorm(20),4,5) vec <- c(1.3297993,…
-
2
votes1
answer1029
viewsQ: Creation of Boxplot in ggplot2
I’m doing some simulations on R. By generating a data.frame and request the impression of boxplots with small sample size and number of samples boxplot is generated perfectly. The problem is when…
-
2
votes2
answers422
viewsA: Code for viewing Boxplot in ggplot2
Another way to solve is to change the part of my chart code g1 where it is written: scale_x_discrete(name = "Valores Estimados", labels=c("gamma0","gamma1","gamma2","beta0", "beta1","beta2","phi1",…
-
3
votes2
answers422
viewsQ: Code for viewing Boxplot in ggplot2
in viewing the boxplot created with the script below, it does not seem to me that the graphics g2, g3 and g4 are the same that appear in the image g1, but I couldn’t find anything wrong in the code!…
-
3
votes1
answer127
viewsQ: Return of the gradient function when using Optim and colSums functions
I can’t understand why when using the function gradlik as a function argument Optim I get the following error: Error in optim(beta, loglik, gradlik, method = "BFGS", hessian = T, control =…
-
1
votes1
answer57
viewsA: R function returns wrong value
When replacing the lines below in the verisimilitude code, the same compiles! Phi_mu2 <- pnorm(-mu2,log.p = TRUE) phi_t0 <- dnorm(term0,log = TRUE) phi_t1 <- dnorm(term1) Phi_t0 <-…
-
1
votes1
answer57
viewsQ: R function returns wrong value
the Log.Lik function below returns the value -INFwhen should return the value -5836.219. I can’t figure out the mistake, anyone has any suggestions? rm(list=ls()) library(ssmrob) data(MEPS2001)…
-
2
votes2
answers57
viewsQ: use of ifelse with Matrix
I need to find the gradient of a function, for this, I’m using the final line of the code below, where it reads: gr2 <- ifelse(y>0,df1bi+df2bi+df3bi+df4bi,dFTbi), note that when compiling the…
-
1
votes2
answers415
viewsA: Import, read and convert cross data to a data frame.
Dear @Weidsonc.Peel, could you improve your questions? Put a larger piece of the spreadsheet and explain better what you want! Regarding reading the database and importing to the R you can use the…
-
2
votes0
answers51
viewsQ: Symbolic operations in the R
I need to multiply two matrices in the R, one has symbolic entries (beta) and the other is a numerical matrix (X), I’ve tried the packages Ryacas and rSymPy, but I couldn’t make it work. After that,…
-
1
votes2
answers155
viewsA: Gradient vector for use in the Optim function
I got a solution for the gradient and I added Hessian, with the three lines of code that are commented in the middle of the script it is possible to verify the coherence of the code! rm(list=ls())…
-
3
votes2
answers155
viewsQ: Gradient vector for use in the Optim function
I have searched a lot, in several forums and in many pages about parameters estimation via function optim of R and found nothing on how to add the gradient function in a script, so that the…
-
3
votes1
answer2281
viewsQ: Select a part of the database in R
I’m doing an evaluation of the database of the transparency portal that can be obtained in this link, The problem is that I would like to select only one part of the database, my assessment is only…
-
3
votes1
answer216
viewsQ: Parameter estimation via mount Rlo and Optim function
I’m doing a study with the bivariate Birnbaum Saunders distribution. To solve my problem I need to create a code that estimates the parameters of a mixed model. Would you like to insert the gradient…
-
1
votes1
answer608
views -
0
votes1
answer437
viewsA: Scoring, Hessian and Newton Raphson function of the exponential distribution in R
Hi @Flaviobarros, thank you for your feedback! I managed to resolve this issue, I apologize for the delay in responding. The reply script is: ## Função escore escore <- function(par, formula,…
-
0
votes1
answer608
views -
5
votes1
answer195
views -
3
votes1
answer88
viewsA: Github pages and rstudio
image error is bizarre, the reason was the date formatting in the file preamble, before my preamble was: title: "Post1" author: "Fernando de Souza Bastos" date: 07 de setembro de 2016 layout: post…
-
2
votes1
answer88
viewsQ: Github pages and rstudio
I’m using the Rstudio to create my documents in the format .Rmd and address in .md with the following function: rmarkdown::render("2016-09-07-post1.Rmd",output_format = "md_document",encoding =…
-
1
votes1
answer110
viewsQ: Parameter estimation using the Optim function
I’m having a problem estimating parameters when using the code below: N=1000 m=matrix(ncol=5,nrow=N) mu1=1.2 mu2=1.5 phi1=1 phi2=2 rho=0.5 n=100 truevalue=c(mu1,mu2,phi1,phi2,rho) for (i in 1:N){…