Displaying 20 results from an estimated 2000 matches similar to: "How would you avoid loops in this simple example?"
2007 Jul 27
4
Q: extracting data from lm
Warning: I am a complete newbie to R. I have read ISwR, but I am still
finding myself completely stuck on some simple concepts.
I have tried everything I can think of to solve this one, and finally
decided that enough was enough and I need a pointer to a solution.
I have the following summary from lm():
----
> summary(lm(nu1~nu4))
Call:
lm(formula = nu1 ~ nu4)
Residuals:
Min 1Q
2009 May 16
1
maxLik pakage
Hi all;
I recently have been used 'maxLik' function for maximizing G2StNV178 function with gradient function gradlik; for receiving this goal, I write the following program; but I have been seen an error in calling gradient function;
The maxLik function can't enter gradlik function (definition of gradient function); I guess my mistake is in line ******** ,that the vector ‘h’ is
2009 May 18
4
MAC OSX vs Win XP: Different stats test results!
Hi all,
I wondered whether anyone has some advice on a stats-related 'sanity check',
as I ran a nonparametric multivariate test (mulrank function as decribed by
R. Wilcox, 2005) on both systems, but got different results (please see
below for the system-specific outputs)! The functions I used are attached as
well. Any advice would be much appreciated! Thanks in advance for getting
back to
2009 Jan 05
1
transform R to C
Dear R users,
i would like to transform the following function from R-code to C-code and call it from R in order to speed up the computation because in my other functions this function is called many times.
`dgcpois` <- function(z, lambda1, lambda2)
{
`f1` <- function(alpha, lambda1, lambda2)
return(exp(log(lambda1) * (alpha - 1) - lambda2 * lgamma(alpha)))
`f2` <-
2008 Nov 22
5
What's the BEST way in R to adapt this vector?
Goal:
Suppose you have a vector that is a discrete variable with values ranging
from 1 to 3, and length of 10. We'll use this as the example:
y <- c(1,2,3,1,2,3,1,2,3,1)
...and suppose you want your new vector (y.new) to be equal in length to the
possible discrete values (3) times the length (10), and formatted in such a
way that if y[1] == 1, then y.new[1:3] == c(1,0,0), and if y[2] ==
2007 Mar 06
2
Estimating parameters of 2 phase Coxian using optim
Hi,
My name is Laura. I'm a PhD student at Queen's University Belfast and have
just started learning R. I was wondering if somebody could help me to see
where I am going wrong in my code for estimating the parameters [mu1, mu2,
lambda1] of a 2-phase Coxian Distribution.
cox2.lik<-function(theta, y){
mu1<-theta[1]
mu2<-theta[2]
lambda1<-theta[3]
2008 Apr 14
5
Equivalent to a BY command in SAS
Hi,
I'm very new to R and absolutely love it. Does anyone know how to use
something in R that functions like a BY command in SAS?
For example, let's say you have a variable x, and you want to see the mean.
Easy...
> mean(x)
But what if you want to see the mean of x conditional on another discrete
variable? My best attempts so far are something like...
> mean(x, y_cat=1)
2008 Sep 12
1
Error in "[<-"(`*tmp*`, i, value = numeric(0)) :
I use "while" loop but it produces an errro. I have no idea about this.
Error in "[<-"(`*tmp*`, i, value = numeric(0)) :
nothing to replace with
The problem description is
The likelihood includes two parameters to be estimated: lambda
(=beta0+beta1*x) and alpha. The algorithm for the estimation is as
following:
1) with alpha=0, estimate lambda (estimate beta0
2006 Jul 07
1
convert ms() to optim()
How to convert the following ms() in Splus to Optim in R? The "Calc" function is also attached.
ms(~ Calc(a.init, B, v, off, d, P.a, lambda.a, P.y, lambda.y,
10^(-8), FALSE, 20, TRUE)$Bic,
start = list(lambda.a = 0.5, lambda.y = 240),
control = list(maxiter = 10, tol = 0.1))
Calc <- function(A.INIT., X., V., OFF., D.,
P1., LAMBDA1., P2., LAMBDA2.,
TOL., MONITOR.,
2008 Sep 26
3
Dealing With Extremely Large Files
Hi,
I'm sure that a large fixed width file, such as 300 million rows and 1,000
columns, is too large for R to handle on a PC, but are there ways to deal
with it?
For example, is there a way to combine some sampling method with read.fwf so
that you can read in a sample of 100,000 records, for example?
Something like this may make analysis possible.
Once analyzed, is there a way to, say, read
2008 Nov 03
4
How do you apply a function to each variable in a data frame?
I want to apply a more complicated function than what I use in my example,
but the idea is the same:
Suppose you have a data frame named x and you want to a function applied to
each variable, we'll just use the quantile function for this example. I'm
trying all sorts of apply functions, but not having luck. My best guess
would be:
sapply(x, FUN=quantile)
--
View this message in
2008 Sep 19
2
Error: function cannot be evaluated at initial parameters
I have an error for a simple optimization problem. Is there anyone knowing
about this error?
lambda1=-9
lambda2=-6
L<-function(a){
s2i2f<-(exp(-lambda1*(250^a)-lambda2*(275^a-250^a))
-exp(-lambda1*(250^a)-lambda2*(300^a-250^a)))
logl<-log(s2i2f)
return(-logl)}
optim(1,L)
Error in optim(1, L) : function cannot be evaluated at initial parameters
Thank you in advance
--
View this
2011 Jul 02
1
Simulating inhomogeneous Poisson process without loop
Dear all
I want to simulate a stochastic jump variance process where N is Bernoulli
with intensity lambda0 + lambda1*Vt. lambda0 is constant and lambda1 can be
interpreted as a regression coefficient on the current variance level Vt. J
is a scaling factor
How can I rewrite this avoiding the loop structure which is very
time-consuming for long simulations?
for (i in 1:N){
...
N <- rbinom(n=1,
2009 Sep 09
2
Matrix multiplication and random numbers
Dear All
I new to using R and am struggling with some matrix multiplication.
I have two matrices, one containing random numbers, these are multiplied
together to get another matrix which is different each time. When I put in
another for loop to repeat this process a multiple times the matrices are
all the same. I?m sure there is a way to keep the randomness of the
different matrices but I think
2012 Sep 19
3
[LLVMdev] counting branch frequencies
Thanks everyone for the replies. After some experimentation, I found
that the order in which the passes are specified matters:
opt -O3 -profile-loader matmult.bc -o matmult.opt.bc (works)
opt -profile-loader -O3 matmult.bc -o matmult.opt.bc (does not work)
Also, I am able to avoid the inconsistency warning only for optimization
levels -O3 and -O2. I get that warning when using -O1 and
2007 Sep 10
2
Are the error messages of ConstrOptim() consisten with each other?
Dear Friends.
I found something very puzzling with constOptim(). When I change the
parameters for ConstrOptim, the error messages do not seem to be
consistent with each other:
> constrOptim(c(0.5,0.3,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
Error in constrOptim(c(0.5, 0.3, 0.5), f = fit.error, gr = fit.error.grr, :
initial value not feasible
> constrOptim(c(0.5,0.9,0.5),
2004 Apr 07
2
Memdisk
Memdisk 2.08 cannot boot an XP boot floppy image (XP appears to use WinME
boot files for its bootable floppy). For example:
http://members.iinet.net.au/~bdriver/bootdisk/download.htm
This disk will not boot with Memdisk (Memdisk starts to load the image and
then hangs). I'm using Bart's tools to build a boot CD:
http://www.nu2.nu/corpmodboot/
Which uses Isolinux and Memdisk.
2011 Jun 14
2
How to generate bivariate exponential distribution?
Any one know is there any package or function to generate bivariate
exponential distribution? I gusee there should be three parameters, two rate
parameters and one correlation parameter. I just did not find any function
available on R. Any suggestion is appreciated.
--
View this message in context:
2008 Jul 28
7
Legality Question about R's Open Source GNU GPL License
Hi,
I use R at home, and am interested in using it at my work company (which is
in the Fortune 100). I began the request, and our legal team has given some
gruff about the open source license. Not boring you with the details here,
but I used some info on gnu.org as a rebuttal, and someone at the company
replied that the generalities of GNU GPL may differ from R's specific GNU
GPL license,
2005 Aug 16
3
how to reshape an array avoiding for loops
Dear r-help,
I have an array a1 with dimensions [1:660,1:65,1:25]
I would like the first dimension to be the last one.
That is I want and array [1:65,1:25,1:660]
The only way to do this, I know, is
tmp.a<-array(dim=dim(a1)[c(2,3,1)])
for(i in 1:dim(a1)[1]) tmp.a[,,i]<-a1[i,,]
a1<-tmp.a
rm(tmp.a)
Is it possible to avoid 'for' loop here?
Thank you!
---