Skip to Content

Questions

R parameters and AIC of function arima() vs auto.arima()

I've got a problem with estimating parameters using functions auto.arima() and arima(). The problem is that when I use auto.arima and get the model with lowest value of AIC, then I try to put appropriate orders p,q,P,Q into function arima() with the same data, I get different value of parameters and different value of AIC. Here is the example:

auto.arima(ddlogvalue, max.p = 3, max.q = 2, max.P = 2, max.Q = 2, start.p = 1,
+ start.q = 1, start.P = 2, start.Q = 2, max.order = 5, ic = "aic")

Code new variable based on grep return in R

I have a variable actor which is a string and contains values like "military forces of guinea-bissau (1989-1992)" and a large range of other different values that are fairly complex. I have been using grep() to find character patterns that match different types of actors.

ddply and categorization function

i would like to categorize a column in a dataframe based on a comparison of subsequent rows.

for:

R trying to get caret / rfe to work

I have a data set that I'm trying to use rfe() from the caret package in R on.

x is the prices I'm trying to predict.

y is the variables I'm using to make the prediction.

I can't get rfe to stop giving the following error message:

> lmProfile2 <- rfe(x1,y1,
+ sizes = subsets,
+ rfeControl = ctrl)
Error in rfe.default(x1, y1, sizes = subsets, rfeControl = ctrl) : 
  there should be the same number of samples in x and y

Here's some info:

Cryptic error message in emacs org-mode following attempted export of file containing image-generating block of R code

I have an R code block that generates an image (see below). Executing the code is no problem (i.e., C-c C-c from within the block generates an image temp.png as expected). However, on export to PDF via LaTeX, there is an error message:

org-babel-sha1-hash: Wrong number of arguments: called-interactively-p, 1

The only other reference to this error (sans the bit about sha1) is from here, http://xahlee.org/emacs/elisp_byte_compile_problem.html in a very diffirent context.

How do I add columns to expand a matrix in R

Sorry I couldn't think of a more informative title, but here's my challenge. I have a matrix and I need to add columns in specific places based on parameters described by a vector. For example, if I have the following matrix:

1, 0, 1, 2, 0
0, 0, 1, 1, 1
1, 1, 0, 0, 0
2, 0, 1, 0, 2

but for a particular R package (unmarked), I need to add columns of NA in specific place. I have a vector relating the columns in the matrix:

GGPLOT2: Distance of discrete values of from each end of x-axis

I have been working with the code below. Everything seems to work
okay, except that the discrete values on the x-axis are far from each
end of the graph. I've tried several things including changing the
discrete values and playing with the limits, but can't get it to work.
I tested this on simulated data and do not have the same problem, so I
guessing it is how I'm processing the data. I'd appreciate any
pointers on how to adjust this and/or process the data correctly so it
does not occur. The data file being imported is a combination of
continuous, discrete and string variables.

R ggplot highlight table of quarterly figures has displaced figures

I am using geom_tile to create a table of quarterly figures, which is contained in a data frame. This seems to work without problems except when the data series begins in the middle of the year, typically in the April to June quarter. If I plot the data frame at the beginning of the calendar year, there is no problem: I get a well-formed highlight table.

However, to achieve that I have also excluded some of my data. If I specify a start date part way through the year, the data gets dispaced/jumbled up, like so:

Making a barplot with known frequencies

Sorry for puting this silly question: I am reading the book "Using R for Introductory Statistics" and would like to create a barplot using this data

install.packages("UsingR")
library(UsingR)
head(scrabble)
 
   piece points frequency
1      A      1         9
4      B      3         2
7      C      3         2
10     D      2         4

The variable piece shows the letter, and the variable frequency its respective frequency in the scrabble game.
Specifically, I would like to have on the X axis the letters, and on the Y axis the frequencies.

the elements of a character vector are lists - how to combine them

given that I have a vector: x <- c("m1", "m2", "m3") and every element m1, m2 and m3 is a list e.g.

m1 = list(a=1:3, b=2:4, c=1:10)  
m2 = list(a=0:3, b=0:4, c=6:10)  
m3 = list(a=1:30, b=1:2, c=6:10)  

I want to be able to create "super list" using loop:

mylist <- list()  
for(i in x)mylist[[i]] <- ...??....  

when i="m1" then mylist[["m1"]] <- m1

any suggestion would be appreciate.

Robert