similar to: A programming question

Displaying 20 results from an estimated 1000 matches similar to: "A programming question"

2012 Jul 13
1
Vuong test
Dear All, I am using the function vuong from pscl package to compare 2 non nested models NB1 (negative binomial I ) and Zero-inflated model. NB1 <-  glm(, , family = quasipoisson), it is an object of class: "glm" "lm" zinb <- zeroinfl( dist = "negbin") is an object of class: "zeroinfl"   when applying vuong function I get the following: vuong(NB1,
2007 Apr 12
3
Random Sequence
Dear Friends, I'm trying to generate a sequence of 100 observations with either a 1 or -1. In other words the sequence should look something like this. y = 1 1 -1 1 -1 -1 -1 1 1 ...... Can somebody please give me some direction on how I can do this in R. Thanks Anup ____________________________________________________________________________________ Don't get soaked. Take a
2007 Apr 18
2
Data Manipulation using R
Dear Friends, I have data set with around 220,000 rows and 17 columns. One of the columns is an id variable which is grouped from 1000 through 9000. I need to perform the following operations. 1) Remove all the observations with id's between 6000 and 6999 I tried using this method. remdat1 <- subset(data, ID<6000) remdat2 <- subset(data, ID>=7000) donedat <- rbind(remdat1,
2013 Jul 14
2
creating dummy variables based on conditions
Hello everyone, I have a dataset which includes the first three variables from the demo data below (year, id and var). I need to create the new variable ans as follows If var=1, then for each year (where var=1), i need to create a new dummy ans which takes the value of 1 for all corresponding id's where an instance of one was recorded. Sample data with the output is shown below. year
2007 Feb 28
3
matrix manipulations
Dear friends, I have a basic question with R. I'm generating a set of random variables and then combining them using the cbind statement. The code for that is given below. for (i in 1:100) { y <- rpois(i,lambda=10) X0 <- seq(1,1,length=i) X1 <- rnorm(i,mean=5,sd=10) X2 <- rnorm(i,mean=17,sd=12) X3 <- rnorm(i,mean=3, sd=24) ind <- rep(1:5,20) }
2007 Jul 06
1
row index
Dear Friends, Suppose I have a vector as follows RI Value 1 10 2 11 3 8 4 4 6 12 I would like a function which returns the"row index number" for the minimum value of VALUE. Can somebody please give me some direction on how I can do this. In effect I'm trying to find a comparable function for the GAUSS command "minindc" >From the GAUSS Manual
2007 Jul 24
1
Passing equations as arguments
Friends, I'm trying to pass an equation as an argument to a function. The idea is as follows. Let us say i write an independent function Ideal Situation: ifunc <- function(x) { return((x*x)-2) } mainfunc <- function(a,b) { evala <- ifunc(a) evalb <- ifunc(b) if (evala>evalb){return(evala)} else return(evalb) } Now I want to try and write this entire program in a single
2007 Sep 08
1
Problem with the aggregate command
Dear friends, I have a data set with 23 columns and 38000 rows. It is a panel running from the years 1991 through 2005. I want to aggregate the data and get the medians of each of the 23 columns for each of the years. In other words my output should be like this Year Median 1991 123 1992 145 1993 132 etc. The sample lines of code to do this operation is set1 <-
2008 Apr 08
2
Metropolis acceptance rates
Is there a way to recover Metropolis-step acceptance rates AFTER completing posterior draws? The immediate application is in the probit.bayes and logit.bayes models used by Zelig... which I believe is merely calling MCMCpack. So one strategy, to which I am fixing to resort, is to call, say, MCMClogit with verbose set to mcmc (or mcmc divided by an integer) and then look at my screen.
2007 Feb 25
3
Random Integers
Hi all, Is there an R function to generate random integers? Thanks in advance. Sincerely Anup --------------------------------- Now that's room service! Choose from over 150,000 hotels [[alternative HTML version deleted]]
2007 Aug 19
1
Creating a data set within a function
Dear Friends, I'm trying to find if there is a way to automate creation of the design matrix. Suppose we are interested in say running an autoregressive model. The user inputs the following data myfunAR <- function(y, order) {..... ...... } now here y is the data series and order represents the level of the process. In other words if order=2 then we have an AR (2) process. Now it is easy
2007 Jun 04
1
Help with conditional lagging of data
Dear Friends, I have some data with three columns named ID, Year and Measure X. I need to create a column which gives me a lag for each ID (note not a continous lag), but a lag conditional on the id and the given year. Please find below a sample of the data Input file sample ID Year X AB12 2000 100 AB12 2001 120 AB12 2002 140 AB12 2003 80 BL14 2000 180 BL14
2007 Jun 22
2
Data consistency checks in functions
Dear friends, I'm writing a function with three arguments myfun <- function(theta, X, values) { .... .... } in this function, I'm trying to write consistency checks. In order to compute the statistic of interest I only need theta and values. The idea of having X in there is that, if values is not provided by the user, then values is computed from X. my problem is I'm trying to
2007 May 30
2
control axis
I have an outlier that I would still like to display, but would prefer to shorten the axis. For example, display 0% - 40%, and 90% - 100%. Is this possible? I am using an xyplot. Thanks Murray -- Murray Pung Statistician, Datapharm Australia Pty Ltd 0404 273 283 [[alternative HTML version deleted]]
2010 Dec 07
1
Help on loops
Dear R-helpers, I have a basic question on using loops. I have a panel data set with different variables measured for "n" firms over "t" time periods. A snapshot of the data is given below id    t    X1    X2 1    1     4    3 1    2    9    2 1    3    7    3 1    4    6    6 2    1    6    4 2    2    5    3 2    3    1    1 3    1    9    6 3    2    5    5 thus total
2008 Nov 21
1
Help with avoiding For Loop
Dear Friends, I'm trying to see if there is some possibility that I can do the following computations without a loop. I have attached a toy example below. A <- c(1,2,3,4,5) B <- rnorm(100) store <- matrix(0,5,2) for (i in 1:5) { store[i,1] <- mean(pnorm(A[i]*B)) store[i,2] <- var(pnorm(A[i]*B)) } store Thanks in advance for your help. Kind Regards Anup [[alternative
2006 Jun 16
6
modeling logit(y/n) using lrm
I have a dataset at a hospital level (as opposed to the patient level) that contains number of patients experiencing events (call this number y), and the number of patients eligible for such events (call this number n). I am trying to model logit(y/n) = XBeta. In SAS this can be done in PROC LOGISTIC or GENMOD with a model statement such as: model y/n = <predictors>;. Can this be done
2011 Oct 19
1
hypothetical prediction after polr
Dear R-Help listers, I am trying to estimate an proportional odds logistic regression model (or ordered logistic regression) and then make predictions by supplying a hypothetical x vector. However, somehow this does not work. I guess I must have missed something here. I first used the polr function in the MASS package, and I create a data frame and supply it to the predict function (see below):
2004 Jun 17
0
beta regression in R
Hello, I'm using optim to program a set of mle regression procedures for non-normal disturbances. This is for teaching and expository purposes only. I've successfully programmed the normal, generalized gamma, gamma, weibull, exponential, and lognormal regression functions. And optim returns reasonable answers for all of these compared with the identical optimization problems in STATA and
2007 May 18
1
Bootstrapped standard errors
Dear Friends, I'm trying to learn to how to get Bootstrapped standard errors for estimated coefficients from a regression. For instance suppose I have the following model logitmodel <- glm (y~X1+X2+X3, family=binomial(link="logit")) beta <- logitmodel$coef can somebody please guide me on how to use the package boot to obtain bootstrapped SE's for the associated betas.