Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 40036

Use this tag for any *on-topic* question that (a) involves `R` either as a critical part of the question or expected answer, & (b) is not *just* about how to use `R`.

1 vote

Proper way to evaluate models fitted to standardized data

You are operating on the mtcars dataset, which has 32 observations and 11 variables (you are predicting mpg using the other 10 variables): dim(mtcars) # [1] 32 11 In your training/testing set split …
josliber's user avatar
  • 4,389
12 votes
Accepted

How to calculate the p.value of an odds ratio in R?

You can use Fisher's exact test, which inputs a contingency table and outputs a p-value, with a null hypothesis that the odds ratio is 1 and an alternative hypothesis that the odds ratio is not equal …
josliber's user avatar
  • 4,389
2 votes
Accepted

Joint expectations in Python or R

For instance, here is the R code to simulate the expected value of $X^2e^Y$ with $\rho = 0.2$ using 1 million samples: # Parameters for calculation f <- function(x) x^2 g <- function(y) exp(y) rho <- …
josliber's user avatar
  • 4,389
9 votes
Accepted

Does runif (R) ever return 0/1

Instead, as I understand it your question is specifically about R, and whether runif will return 0 or 1 due to the finite numerical precision of your computer. We can read the following from ? … So we conclude that drawing from the standard uniform distribution in R using runif will never return 0 or 1. …
josliber's user avatar
  • 4,389
2 votes

data analysis about data clustering by vector correlation distance

It seems like you want to use a distance metric based on correlation, so you could assign a "dissimilarity score" between pairs of points based on correlation; I'll use 1-cor(a, b) to compute the diss …
josliber's user avatar
  • 4,389
4 votes

R: Box-plot on log scale vs. log-transforming *then* creating box-plot: Don't get same result

From ?boxplot, you can read: range this determines how far the plot whiskers extend out from the box. If range is positive, the whiskers extend to the most extreme data point which is no …
josliber's user avatar
  • 4,389
6 votes

Discrepancy in Cholesky decomposition matrix from variance covariance matrix obtained in Sta...

Meanwhile, from the R documentation, chol returns an upper triangular matrix $M$ such that $X = M'M$ for input matrix $X$. From this we would expect them to be transposes of each other. … However, the outputs differ even more significantly because R and Stata have flipped the variable ordering -- the R function lists intercept first and expense second, while Stata lists expense first and …
josliber's user avatar
  • 4,389
15 votes
Accepted

Predicted probability values from Logistic regression are negative

From ?predict.glm, you can read that by default the type of prediction will be the link function (log odds for logistic regression) instead of probabilities. You can get predicted probabilities with …
josliber's user avatar
  • 4,389
4 votes

plotting a factorial function in R

Another way to write this by cancellation would be: $$ P(D|N) = \frac{60\times 59\times\ldots\times 51\times(N-60)\times(N-61)\times\ldots\times(N-149)}{N\times(N-1)\times(N-99)} $$ Note that the nu …
josliber's user avatar
  • 4,389
7 votes
Accepted

Calculating MAPE

From the name Mean Absolute Percentage Error, there needs to be an absolute value in the calculation of MAPE: rowMeans(abs((actual-predicted)/actual) * 100) This matches the formula for MAPE at, fo …
josliber's user avatar
  • 4,389
1 vote
Accepted

glmer.nb does not converge when one variable is included in the model

The warning messages you received are informative here: 2: Some predictor variables are on very different scales: consider rescaling So it seems like a good approach is to rescale some variabl …
josliber's user avatar
  • 4,389