similar to: Create a vector from another vector

Displaying 20 results from an estimated 6000 matches similar to: "Create a vector from another vector"

2011 Dec 01
1
Estimation of AR(1) Model with Markov Switching
Dear R users, I have been trying to obtain the MLE of the following model state 0: y_t = 2 + 0.5 * y_{t-1} + e_t state 1: y_t = 0.5 + 0.9 * y_{t-1} + e_t where e_t ~ iidN(0,1) transition probability between states is 0.2 I've generated some fake data and tried to estimate the parameters using the constrOptim() function but I can't get sensible answers using it. I've tried using
2006 Apr 19
4
Basic vector operations was: Function to approximate complex integral
Dear List I apologize for the multiple postings. After being in the weeds on this problem for a while I think my original post may have been a little cryptic. I think I can be clearer. Essentially, I need the following a <- c(2,3) b <- c(4,5,6) (2*4) + (2*5) + (2*6) + (3*4) + (3*5) +(3*6) But I do not know of a built in function that would do this. Any suggestions? -----Original
2012 Jan 25
1
function restrictedparts
I am using function restrictedparts, but got error: restrictedparts(281,10) Error in integer(len) : vector size specified is too large Calls: restrictedparts -> integer In addition: Warning message: In restrictedparts(281, 10) : NAs introduced by coercion Error in integer(len) : vector size specified is too large Calls: restrictedparts -> integer is there a similar function can deal with
2012 Jan 23
3
How can I access information stored after I run a command in R?
Dear all, Supposed I run the following command: ############################### #install.packages("Rassoc", dependencies=TRUE) library("Rassoc") ca=c(139,249,112) co=c(136,244,120) a=rbind(ca,co) MAX3(a,"asy",1) ############################## I get: The MAX3 test using the asy method data: a statistic = 0.5993, p-value = 0.7933 How can one save the result
2009 Dec 28
2
Modified R Code
Dear R helpers,   I have following input files. (Actually they are more than 10 rates but here i am considering only 2 rates to write my problem)   rate1.csv min1        max1            min2          max2          min3           max3 1.05        1.30               1.30          1.65             1.65          1.99   rate2.csv min1        max1            min2          max2          min3          
2006 Jul 19
4
Wrap a loop inside a function
I need to wrap a loop inside a function and am having a small bit of difficulty getting the results I need. Below is a replicable example. # define functions pcm <- function(theta,d,score){ exp(rowSums(outer(theta,d[1:score],'-')))/ apply(exp(apply(outer(theta,d, '-'), 1, cumsum)), 2, sum) } foo <- function(theta,items, score){ like.mat <-
2006 Apr 19
1
Function to approximate complex integral
I am writing a small function to approximate an integral that cannot be evaluated in closed form. I am partially successful at this point and am experiencing one small, albeit important problem. Here is part of my function below. This is a psychometric problem for dichotomously scored test items where x is a vector of 1s or 0s denoting whether the respondent answered the item correctly (1) or
2016 Nov 08
2
should we have IR intrinsics for integer min/max?
Thanks, Hal and Matt for the feedback. As usual, my instincts about canonicalization were probably wrong. :) I thought that @max1 vs. @max3 would be viewed as an unknowable trade-off between reducing the dependency chain and the pseudo-canonical min/max form, so we'd add intrinsics, and defer that decision to the backend. I'll wait to see if there are any other arguments presented.
2006 Aug 24
1
Optim question
This is a very basic question, but I am a bit confused with optim. I want to get the MLEs using optim which could replace the newton-raphson code I have below which also gives the MLEs. The function takes as input a vector x denoting whether a respondent answered an item correctly (x=1) or not (x=0). It also takes as input a vector b_vector, and these are parameters of test items (Rasch estimates
2016 Nov 07
5
should we have IR intrinsics for integer min/max?
Hi - The answer to this question may help to resolve larger questions about intrinsics and vectorization that were discussed at the dev mtg last week, but let's start with the basics: Which, if any, of these is the canonical IR? ; ret = x < y ? 0 : x-y define i32 @max1(i32 %x, i32 %y) { %sub = sub nsw i32 %x, %y %cmp = icmp slt i32 %x, %y ; cmp is independent of sub %sel = select
2006 Jul 20
2
Timing benefits of mapply() vs. for loop was: Wrap a loop inside a function
List: Thank you for the replies to my post yesterday. Gabor and Phil also gave useful replies on how to improve the function by relying on mapply rather than the explicit for loop. In general, I try and use the family of apply functions rather than the looping constructs such as for, while etc as a matter of practice. However, it seems the mapply function in this case is slower (in terms of CPU
2010 Jun 02
1
Use apply only on non-missing values
I have a function that I am currently using very inefficiently. The following are needed to illustrate the problem: set.seed(12345) dat <- matrix(sample(c(0,1), 110, replace = TRUE), nrow = 11, ncol=10) mis <- sample(1:110, 5) dat[mis] <- NA theta <- rnorm(11) b_vector <- runif(10, -4,4) empty <- which(is.na(t(dat))) So, I have a matrix (dat) with some values within the matrix
2011 Oct 11
2
stop()
Suppose I have a function, such as the toy example below: myFun <- function(x, max.iter = 5) { for(i in 1:10){ result <- x + i iter <- i if(iter == max.iter) stop('Max reached') } result } I can of course do this: myFun(10, max.iter = 11) However, if I reach the maximum
2005 Jul 29
3
Error Downloading Matrix Package
I'm trying to update my Matrix package given the update last night. But the following error is generated. I've tried restarting R and deleting my old Matrix package. Can anyone suggest how this might be resolved? > install.packages('Matrix') trying URL 'http://www.ibiblio.org/pub/languages/R/CRAN/bin/windows/contrib/2.1/Mat rix_0.98-1.zip' Content type
2005 Dec 01
1
Simulate Correlated data from complex sample
Dear List: I have created some code to simulate data from a complex sample where 5000 students are nested in 50 schools. My code returns a dataframe with a variable representing student achievement at a single time point. My actual code for creating this is below. What I would like to do is generate a second column of data that is correlated with the first at .8 and has the same means within
2012 Jun 01
1
R Error : Error in vector("list", gamma(n + 1)) : vector size specified is too large
Dear R-listers, I am giving part of my R code : ########################################################### n=15 m=1 library("partitions") library("gregmisc") library("combinat") x = t(restrictedparts(n-m,m)) l = length(x[,1]) for(u in 1:l){ A= unique(matrix( unlist(permn(x[u,])), ncol=m, byrow=TRUE )) }
2009 Nov 29
1
optim or nlminb for minimization, which to believe?
I have constructed the function mml2 (below) based on the likelihood function described in the minimal latex I have pasted below for anyone who wants to look at it. This function finds parameter estimates for a basic Rasch (IRT) model. Using the function without the gradient, using either nlminb or optim returns the correct parameter estimates and, in the case of optim, the correct standard
2005 Sep 09
1
Off-topic: Comparing standard errors from simulation and analytical model
Dear list: I'm hoping to tap in to the statistical expertise in the group, especially those familiar with simulation techniques. I'm finalizing a study where I obtain standard errors from two sources. The first source is a monte carlo simulation and the other source is an analytical model I have developed that appears to recover the standard errors from the simulation. All analysis are
2008 Sep 24
4
rowSums()
Say I have the following data: testDat <- data.frame(A = c(1,NA,3), B = c(NA, NA, 3)) > testDat A B 1 1 NA 2 NA NA 3 3 3 rowsums() with na.rm=TRUE generates the following, which is not desired: > rowSums(testDat[, c('A', 'B')], na.rm=T) [1] 1 0 6 rowsums() with na.rm=F generates the following, which is also not desired: > rowSums(testDat[, c('A',
2009 Oct 21
1
formula and model.frame
Suppose I have the following function myFun <- function(formula, data){ f <- formula(formula) dat <- model.frame(f, data) dat } Applying it with this sample data yields a new dataframe: qqq <- data.frame(grade = c(3, NA, 3,4,5,5,4,3), score = rnorm(8), idVar = c(1:8)) dat <- myFun(score ~ grade, qqq) However, what I would like is for the resulting dataframe (dat) to include