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

learn more… | top users | synonyms

4
votes
2answers
2k views

Number of trials required from a binomial distribution to get the desired odds

This question may have been asked before, but I couldn't find it. So, here goes. From about 3000 data points that can be characterized as "wins" or "losses" (binomial), it turns out that there are ...
2
votes
2answers
566 views

Repeated measures using R

How do I carry out a repeated measures analysis using R?
21
votes
4answers
7k views

How do I fit a multilevel model for over-dispersed poisson outcomes?

I want to fit a multilevel GLMM with a Poisson distribution (with over-dispersion) using R. At the moment I am using lme4 but I noticed that recently the ...
10
votes
1answer
660 views

Documented/reproducible examples of successful real-world applications of econometric methods?

This question might sound very broad, but here is what I am looking for. I know there are many excellent books about econometric methods, and many excellent expository articles about econometric ...
3
votes
1answer
177 views

Function timings in the Matrix package

In order to test the Matrix package in R, I ran the following piece of code: ...
2
votes
1answer
522 views

Aggregating results from Arima runs R

/edit: To clarify: The mtable function from the memisc package does exactly what I need, but unfortunately does not work with arima models. Similar to this question: I have multiple Arima models, ...
1
vote
2answers
996 views

How to pull data formatted for Matlab into R?

I just ran a vendor-supplied program that converts data from their proprietary binary format to what they call a "Matlab format". There are two resulting files from the conversion, a "filename.dat" ...
6
votes
1answer
4k views

Simulation of ARIMA (1,1,0) series

I have fitted the ARIMA models to the original time series, and the best model is ARIMA(1,1,0). Now I want to simulate the series from that model. I wrote the simple AR(1) model, but I couldn't ...
5
votes
1answer
739 views

The code variable in the nlm() function

In R there is a function nlm() which carries out a minimization of a function f using the Newton-Raphson algorithm. In particular, that function outputs the value of the variable code defined as ...
3
votes
1answer
836 views

How to do a logistic regression with the results of different factor analysis methods

I have a large amount of variables (24) to predict a Y/N value, and I would like help for writting a procedure that automatically tries the different results of the factor selection to see how good ...
6
votes
2answers
11k views

zscore function in R

I am unable to get the zscore function to work. When I try to call it, I get the following error: ...
8
votes
2answers
4k views

Calculating p-value from an arbitrary distribution

I hope this isn't a silly question. Let's say I have some arbitrary continuous distribution. I also have a statistic, and I'd like to use this arbitrary distribution to get a p-value for this ...
8
votes
3answers
900 views

How can I speed up calculation of the fixed effects in a GLMM?

I'm doing a simulation study which requires bootstrapping estimates obtained from a generalized linear mixed model (actually, the product of two estimates for fixed effects, one from a GLMM and one ...
8
votes
1answer
2k views

How could a Tukey HSD test be more signif then the uncorrected P value of t.test?

I came by the post "Post-hoc Pairwise Comparisons of Two-way ANOVA" (responding to this post), which shows the following: ...
5
votes
3answers
5k views

Plotting a heatmap given a dendrogram and a distance matrix in R

I have dendrogram and a distance matrix. I wish to compute a heatmap -- without re-doing the distance matrix and clustering. Is there a function in R that permits this?
10
votes
2answers
4k views

Split-Plot ANOVA: model comparison tests in R

How can I test effects in a Split-Plot ANOVA using suitable model comparisons for use with the X and M arguments of ...
15
votes
2answers
2k views

Aggregating results from linear model runs R

Since regression modeling is often more "art" than science, I often find myself testing many iterations of a regression structure. What are some efficient ways to summarize the information from these ...
7
votes
2answers
3k views

cforest and randomForest classification prediction error

I used cforest and randomForest for a 300 rows and 9 columns dataset and received good (almost overfitted - error equal to zero) results for randomForest and big prediction errors for cforest ...
5
votes
2answers
5k views

Efficient way to populate matrix in R?

Given a table comprising three columns, 1 2 0.05 1 3 0.04 2 3 0.001 and a matrix with defined dimensions, ...
9
votes
4answers
2k views

Building MATLAB and R interfaces to Ross Quinlan's C5.0

I'm considering building MATLAB and R interfaces to Ross Quinlan's C5.0 (for those not familiar with it, C5.0 is a decision tree algorithm and software package; an extension of C4.5), and I am trying ...
4
votes
3answers
4k views

Splitting a numeric column for a dataframe

I have a dataframe df as shown below name position 1 HLA 1:1-15 2 HLA 1:2-16 3 HLA 1:3-17 I would like to split the ...
12
votes
4answers
1k views

Setting up Sweave, R, Latex, Eclipse StatET

A few days ago I saw a post on how to setup a SweaveR, which would allow for a user to directly export things like tables, graphs, etc. into Latex. I couldn't quite follow the directions. Can anyone ...
6
votes
1answer
2k views

Plotting binomial proportions on a box & whiskers plot using R

Apologies in advance - I'm a bit of a newbie with R but I've been Google-ing this for weeks and I haven't found a straight answer. The problem Basically, I'm looking to plot proportions with their ...
4
votes
2answers
928 views

Understanding expectation maximization for simple 2 linear mixture case

I would appreciate some help getting some EM stuff straight. So, say I generate data in R as follows: ...
6
votes
1answer
1k views

How to compute Confidence Interval associated to a Binomial proportion's increase?

Not sure if you can help me but here's the problem. I have two binomial proportions A and B (95% CI) - $A = 2\% \pm 0.2\%,\quad B = 3\% \pm 0.2\%.$ In other words, B's proportion is 50% higher than ...
25
votes
2answers
66k views

Removing duplicated rows data frame in R [closed]

How can I remove duplicate rows from this example data frame? A 1 A 1 A 2 B 4 B 1 B 1 C 2 C 2 I would like to remove the duplicates based on ...
7
votes
1answer
4k views

1-step-ahead predictions with dynlm R package

I've fit a model with several independent variables, one of which is the lag of the dependent variable, using the dynlm package. Assuming I have 1-step-ahead forecasts for my independent variables, ...
9
votes
2answers
3k views

Difference between ridge regression implementation in R and SAS

I have been reading the description of ridge regression in Applied Linear Statistical Models, 5th Ed chapter 11. The ridge regression is done on body fat data available here. The textbook matches ...
8
votes
1answer
2k views

Using Singular Value Decomposition to Compute Variance Covariance Matrix from linear regression model

I have a design matrix of p regressors, n observations, and I am trying to compute the sample variance-covariance matrix of the parameters. I am trying to directly calculate it using svd. I am using ...
25
votes
2answers
8k views

Understanding the parameters inside the Negative Binomial Distribution

I was trying to fit my data into various models and figured out that the fitdistr function from library MASS of ...
4
votes
2answers
4k views

Regression selection using all possible subsets selection and automatic selection techniques

Given the dataset cars.txt, we want to formulate a good regression model for the Midrange Price using the variables Horsepower, Length, Luggage, Uturn, Wheelbase, and Width. Both: using all possible ...
7
votes
1answer
132 views

Can someone help me understand what type of problem I am looking at? Not sure if this classifies as hypothesis-testing

Please pardon me if this question is not clear. I am not sure if I am using the right terminologies. I have conducted an experiment in different environments multiple times. So my data looks ...
5
votes
2answers
3k views

How do I generate a QQ-Plot for data fitted using fitdistr?

I am doing the following to fit my data using an exponential function: ...
7
votes
4answers
2k views

Predict after running the mlogit function in R

Here's what I want to do, but there seem to be no predict method for the mlogit. Any ideas? ...
4
votes
3answers
303 views

What is the difference between Rf_dpois in Rmath.h and the dpois that I use directly in R?

If I see Rmath.h in /usr/share/R/include, the signature of the function dpois or ...
2
votes
2answers
5k views

How can one use the predict function on a lm object where the IVs have been dynamically scaled?

Note: I've updated the example case code, there were some errors in the previous version Cross posted to R-help, because I half suspect this is 'unexpected behaviour'. I want to predict values from ...
2
votes
2answers
328 views

Need to convert duplicate column elements to a unique element in R

I need to convert the table A to table B. How can I do that using R? TABLE A Y 10 Y 12 Y 18 X 22 X 12 Z 11 Z 15 TABLE B ...
7
votes
1answer
2k views

Statistical test for trend (continuous variable) in Stata or R

I have serial hematological measurements data and I have plotted their means and SE in Stata. On the y-axis I have for example hemoglobin and time (visit days) on the x-axis hence I can visualize ...
2
votes
2answers
3k views
7
votes
4answers
611 views

How can I estimate the density of a zero-inflated parameter in R?

I have a data set with lots of zeros that looks like this: set.seed(1) x <- c(rlnorm(100),rep(0,50)) hist(x,probability=TRUE,breaks = 25) I would like to draw ...
18
votes
3answers
18k views

What is Deviance? (specifically in CART/rpart)

What is "Deviance," how is it calculated, and what are its uses in different fields in statistics? In particular, I'm personally interested in its uses in CART (and its implementation in rpart in R). ...
2
votes
1answer
366 views

Investigate ratios between two groups

I've got some data that has this basic shape (using R): ...
2
votes
1answer
328 views

What types of analysis are appropriate for demographic time series data?

Let us say we have some demographic time series data which tells us how many hours people spend in front of a computer screen each day, grouped by age and gender: ...
3
votes
1answer
581 views

Collapsing categorical data easily for regression in R

I have read an article from Christopher Manning, and saw an interesting code for collapsing categorical variable in an logistic regression model: ...
8
votes
2answers
5k views

How can one plot continuous by continuous interactions in ggplot2?

Let's say I have data: ...
5
votes
1answer
184 views

Getting started on BUGS, need help implementing a simple model

If I have a parameter with a prior $X\sim N(\mu,\sigma)$ and three data points, $x_1,x_2,x_3$, how can I calculate the posterior in R or BUGS? Here is an attempt at doing this in BUGS, that I have ...
3
votes
2answers
628 views

Reading random text file in R

I have about 500 text documents stored in a directory. I want to randomly select one to read in the contents (this process will be repeated several times). The names of the files are not sequential. ...
7
votes
3answers
3k views

Predicting from a simple linear model with lags in R

I have a dataset that I want to fit a simple linear model to, but I want to include the lag of the dependent variable as one of the regressors. Then I want to predict future values of this time series ...
2
votes
2answers
519 views

How can I plot this simple graph (Refer Image) in R?

I'm very new to R Programming. So please excuse for such a simple doubt. I want to plot the above graph. The x & y values are sequence from 0 to 2560. I want plot a a curve on the points where ...
7
votes
2answers
3k views

Predicting daily electricity load - fitting time series

I want to predict inter-day electricity load. My data are electricity loads for 11 months, sampled in 30 minute intervals. I also got the weather-specific data from a meteorological station ...