Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [r]

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`.

6
votes
3answers
643 views

How to build an “equilibrated histogram”?

I would like to create an "equilibrated histogram" with roughly the same number of data points in each bin. The second restriction I have is that I should have only 4 bins. Given the following list of ...
5
votes
2answers
6k views

Is there a limit function in R?

Is there a 'limit' function in R? help(lim) or help(limit) weren't useful. And in general, is R suitable for mathematical ...
3
votes
4answers
512 views

Automating model selection criteria production

I want to perform model comparison according to several criteria using R. My dataframe's name is df ...
31
votes
1answer
6k views

For which distributions are the parameterizations in BUGS and R different?

I have found some distributions for which BUGS and R have different parameterizations: Normal, log-Normal, and Weibull. For each of these, I gather that the second parameter used by R needs to be ...
5
votes
6answers
14k views

Get the number of parameters of a linear model

Is there a way to get the number of parameters of a linear model like that? model <- lm(Y~X1+X2) I would like to get the number 3 somehow (intercept + X1 + X2)...
12
votes
2answers
6k views

How can one do an MCMC hypothesis test on a mixed effect regression model with random slopes?

The library languageR provides a method (pvals.fnc) to do MCMC significance testing of the fixed effects in a mixed effect regression model fit using lmer. However, pvals.fnc gives an error when the ...
3
votes
2answers
147 views

What else can be deduced from the following class grade summary information?

Lets say for example a class of students and their grades are the data set. Lets say there are around 35 students. Here is what you know: ...
5
votes
2answers
2k views

DLM results looking wonky

I am teaching myself DLM's using R's dlm package and have two strange results. I am modeling a time series using three combined elements: a trend (...
5
votes
2answers
2k views

Estimate the “meaningful” predictors for a value in a CART model (rpart)

When building a CART model (specifically classification tree) using rpart (in R), it is sometimes obvious that there are variables (X's) that are meaningful for predicting some of the outcome (y) ...
5
votes
3answers
8k views

No valid coefficients for NegBin regression

I am doing multiple regression with some data (5 predictors, 1 response). Since the response is discrete and non-negative, I thought I would try Poisson regression. However, the data are significantly ...
47
votes
5answers
2k views

First R packages source code to study in preparation for writing own package

I'm planning to start writing R packages. I thought it would be good to study the source code of existing packages in order to learn the conventions of package construction. My criteria for good ...
11
votes
4answers
7k views

Clustering (k-means, or otherwise) with a minimum cluster size constraint

I need to cluster units into $k$ clusters to minimize within-group sum of squares (WSS), but I need to ensure that the clusters each contain at least $m$ units. Any idea if any of R's clustering ...
36
votes
2answers
91k views

Logistic regression model does not converge

I've got some data about airline flights (in a data frame called flights) and I would like to see if the flight time has any effect on the probability of a ...
13
votes
1answer
7k views

Calculate Newey-West standard errors without an lm object in R

I asked this question yesterday on StackOverflow, and got an answer, but we agreed that it seems a bit hackish and there may be a better way to look at it. The question: I would like calculate the ...
37
votes
9answers
8k views

How can I efficiently model the sum of Bernoulli random variables?

I am modeling a random variable ($Y$) which is the sum of some ~15-40k independent Bernoulli random variables ($X_i$), each with a different success probability ($p_i$). Formally, $Y=\sum X_i$ where $\...
81
votes
4answers
42k views

How to choose nlme or lme4 R library for mixed effects models?

I have fit a few mixed effects models (particularly longitudinal models) using lme4 in R but would like to really master the ...
3
votes
1answer
4k views

Interpreting correlation from two linear mixed-effect models

I have a linear mixed-effect model which I hope will answer the question of whether an increase in the frequency of use of one word leads to an increase of the frequency of use of that word by another ...
6
votes
3answers
5k views

How do I setup up repeated measures data for analysis with nlme()?

I'm trying to transition to R from using SPSS. In the past, I've setup my data in the wide format for my repeated measures ...
9
votes
3answers
6k views

How to re-sample an XTS time series in R?

I have an irregularly spaced XTS time series (with POSIXct values as index type). How can I build a new time series sampled at ...
30
votes
3answers
17k views

Why is there a difference between manually calculating a logistic regression 95% confidence interval, and using the confint() function in R?

Dear everyone - I've noticed something strange that I can't explain, can you? In summary: the manual approach to calculating a confidence interval in a logistic regression model, and the R function <...
6
votes
2answers
3k views

Find out pseudo R square value for a Logistic Regression analysis [closed]

My name is Tuhin. I came up with a couple of questions when I was doing an analysis in R. I did a logistic regression analysis in R and tried to check how good the model fits the data. But, I got ...
73
votes
15answers
120k views

Good GUI for R suitable for a beginner wanting to learn programming in R?

Is there any GUI for R that makes it easier for a beginner to start learning and programming in that language?
1
vote
1answer
10k views

How to change X-axis format in plot

I have fit a linear model and I now doing a lack-of-fit test. If the model has a good fit, the residual deviance should follow a $\chi^2$ distribution. The model I just ran has a very poor fit, and ...
2
votes
1answer
2k views

Interpreting size and direction of fixed effects in a linear mixed effect model

I have some data which, after lots of searching, I concluded would probably benefit from using a linear mixed effects model. I think I have an interesting result here, but I am having a little trouble ...
4
votes
2answers
540 views

Analysis with binomial outcome and categorical predictor

I have a need to analyze an experiment that had a binomial outcome and categorical predictors. For context we sent out an email to our customers and encouraged them to register their account online (...
147
votes
2answers
625k views

How do I get the number of rows of a data.frame in R? [closed]

After reading a dataset: dataset <- read.csv("forR.csv") How can I get R to give me the number of cases it contains? Also, will the returned value include of ...
30
votes
1answer
32k views

Multiple comparisons on a mixed effects model

I am trying to analyse some data using a mixed effect model. The data I collected represent the weight of some young animals of different genotype over time. I am using the approach proposed here: ...
4
votes
2answers
2k views

How to calculate the probability for pattern that violates “control chart rules” to occur?

I am going to host a training session to teach healthcare staff how to use control chart (c-chart to be specific), and I need to tell that why these rules (Western Electric Rules) are so called rules ...
4
votes
4answers
275 views

Visualizing the distribution of something within a very large body of data

Say I have a database of around a million words, and I want to get an intuitive idea about exactly how a particular, quite infrequent, word is distributed throughout this data. My goal is to be able ...
8
votes
2answers
1k views

Is sample kurtosis hopelessly biased?

I am looking at the sample kurtosis of a fairly skewed random variable, and the results seem inconsistent. To simply illustrate the problem, I looked at the sample kurtosis of a log-normal RV. In R (...
1
vote
1answer
701 views

How do you calculate simple statistics for left censored data in R?

I have left censored data where the distribution is known (it's near enough lognormal, at least in theory). I'd like to calculate some simple summary stats: geometric mean and standard deviation in ...
8
votes
2answers
5k views

Yates' continuity correction in confidence interval returned by prop.test

This is the confidence interval estimated by prop.test ...
10
votes
4answers
13k views

How to draw funnel plot using ggplot2 in R?

As title, I need to draw something like this: Can ggplot, or other packages if ggplot is not capable, be used to draw something like this?
6
votes
1answer
3k views

Getting started with time series in R

With some great help from this forum, I have been able to get up and running with some basic time series analysis in R. Right now, my needs are mostly univariate time series. Here is my question: ...
4
votes
3answers
3k views

Using R2WinBUGS, how to extract information from each chain?

I am new to Gibbs Sampling, and have been using WinBUGS, but I find that it is not well-suited towards storing/presenting results, so I have been calling it from R using the R2WinBUGS package. The ...
2
votes
1answer
4k views

Starting out with forecast package in R

I am new to forecasting in R and am trying to automatically fit an ARIMA model to what I believe is a univariate dataset. ...
17
votes
2answers
5k views

Nonparametric Bayesian analysis in R

I am looking for a good tutorial on clustering data in R using hierarchical dirichlet process (HDP) (one of the recent and popular nonparametric Bayesian methods). ...
226
votes
2answers
158k views

Interpretation of R's lm() output

The help pages in R assume I know what those numbers mean, but I don't. I'm trying to really intuitively understand every number here. I will just post the output and comment on what I found out. ...
8
votes
4answers
303 views

Seeking a distribution, perhaps uncommon, consistent with two data points and expert constraints?

I am trying to state a prior distribution for a Bayesian meta-analysis. I have the following information about a random variable: Two observations: 3.0, 3.6 a scientist who studies the variable has ...
6
votes
1answer
1k views

Gaussian state space forecasting with regression effects

The R package dlm implements filtering and smoothing (dlmFilter and dlmSmooth) for models with regression effects, but ...
7
votes
1answer
1k views

Use coefficients of thin plate regression splines in a clustering method

There are numerous procedures for functional data clustering based on orthonormal basis functions. I have a series of models built with the GAMM models, using the ...
3
votes
2answers
5k views

Confidence-intervals for conditions tested with a mixed-effects model

Sorry for a possibly ignorant question. I have fit a mixed-effects model using the lmer function from the lme4 package, and the main fixed effect (a factor with three levels) in the model was ...
15
votes
2answers
2k views

Hit and run MCMC

I'm trying to implement the hit and run MCMC algorithm, but I'm having a bit of trouble understanding how to go about it. The general idea, is as follows: To generate a proposal jump in MH, we: ...
6
votes
3answers
7k views

Stacked bar plot

I have a data-frame whose first column is the name of an item and the second column is the frequency of that item in the dataset. ...
4
votes
1answer
1k views

Is there any relation between Power Law and Negative Binomial distribution?

In a social experiment that I was conducting, I was trying to count the number of people each user contacted in a period of 10 days. The population size was 100 for the experiment. Based on the values ...
7
votes
1answer
1k views

What are the ANOVA's benefits over a normal linear model?

I'm experimenting with R and found that an anova() needs an object of type lm. But why should I continue with an anova after this: ...
57
votes
2answers
119k views

How can I change the title of a legend in ggplot2? [closed]

I have a plot I'm making in ggplot2 to summarize data that are from a 2 x 4 x 3 celled dataset. I have been able to make panels for the 2-leveled variable using ...
10
votes
3answers
2k views

Estimating parameters of a dynamic linear model

I want to implement (in R) the following very simple Dynamic Linear Model for which I have 2 unknown time varying parameters (the variance of the observation error $\epsilon^1_t$ and the variance of ...
4
votes
1answer
2k views

Multi-stage selection model with panel data in R

My data consists of individual level observations nested within countries over time. I would like to use multilevel models along with some sort of selection model. I have three related questions. ...
3
votes
1answer
3k views

Understanding a Quantile-Quantile Plot [duplicate]

I must have generated at least 5 Q-Q plots until now when trying to fit my data into a known distribution but I just noticed something that I could not understand. In the figure shown below, from what ...