similar to: Code to replace nested for loops

Displaying 20 results from an estimated 6000 matches similar to: "Code to replace nested for loops"

2012 Jan 05
2
Bayesian estimate of prevalence with an imperfect test
Hi all! I'm new to this forum so please excuse me if I don't conform perfectly to the protocols on this board! I'm trying to get an estimate of true prevalence based upon results from an imperfect test. I have various estimates of se/sp which could inform my priors (at least upper and lower limits even if with a uniform distribution) and found the following code on this website..
2009 Jun 04
0
Dropping terms from regression w/ poly()
Hello r-help, I'm fitting a model with lm() and using the orthogonal polynomials from poly() as my basis: dat <- read.csv("ConsolidatedData.csv", header=TRUE) attach(dat) nrows <- 1925 Rad <- poly(Radius, 2) ntheta <- 14 Theta <- poly(T.Angle..deg., ntheta) nbeta <- 4 Beta <- poly(B.Beta..deg., nbeta) model.1 <- lm( Measurement ~ Block + Rad + Theta + Beta
2006 Sep 19
0
How to interpret these results from a simple gamma-frailty model
Dear R users, I'm trying to fit a gamma-frailty model on a simulated dataset, with 6 covariates, and I'm running into some results I do not understand. I constructed an example from my simulation code, where I fit a coxph model without frailty (M1) and with frailty (M2) on a number of data samples with a varying degree of heterogeneity (I'm running R 2.3.1, running takes ~1 min).
2003 Aug 13
4
Levene test of homogeneity of variance
Has the Levene test of homogeneity of variance been implemented in any library in R? Thanks, Maurice Haynes National Institute of Child Health and Human Development Child and Family Research Section 6705 Rockledge Drive Bethesda, MD 20892 Voice: 301-496-8180 Fax: 301-496-2766 E-Mail: mh192j at nih.gov
2004 Dec 21
3
R code for var-cov matrix given variances and correlations
Dear list members, Where can I find code for computing the p*p variance-covariance matrix given a vector of p variances (ordered varA, varB, ..., varp) and a vector of all possible correlations (ordered corAB, corAC, ..., corp-1,p)? I know that the covariance between 2 variables is equal to the product of their correlation and their standard deviations: corAB * varA^.5 * varB^.5 and so:
2009 Aug 31
1
package installation error
On Sun April 19, you posted the following on R-help: > After installing 2.9.0 I tried loading packages, but keep getting the following error. > > package 'robustbase' successfully unpacked and MD5 sums checked > Error in normalizePath(path) : > path[1]="C:\Program Files\R\R-2.9.0\library/robustbase": The system cannot find the file specified > I have had the
2012 Mar 14
1
Metropolis-Hastings in R
Hi all, I'm trying to write a MH algorithm in R for a standard normal distribution, I've been trying for a good week or so now with multiple attempts and have finally given up trying to do it on my own as I'm beginning to run out of time for this, would somebody please tell me what is wrong with my latest attempt: n=100 mu=0 sigma=1 lik<-function(theta) exp(((theta-mu)^2)/2*sigma)
2008 Aug 26
2
Problem with Integrate for NEF-HS distribution
I need to calcuate the cumulative probability for the Natural Exponential Family - Hyperbolic secant distribution with a parameter theta between -pi/2 and pi/2. The integration should be between 0 and 1 as it is a probability. The function "integrate" works fine when the absolute value of theta is not too large. That is, the NEF-HS distribution is not too skewed. However, once the
2002 Nov 27
2
Error message: missing value where logical needed
Dear all, I often import data sets from other programs that contain user defined missing values. As an example consider a variable MXPLOCO with a user defined missing value of as -9. > summary(MXPLOCO) Min. 1st Qu. Median Mean 3rd Qu. Max. NA's -9.000 4.750 5.000 5.349 6.000 8.500 2.000 The following command successfully converts the value -9 to NA. However,
2011 May 04
1
hurdle, simulated power
Hi all-- We are planning an intervention study for adolescent alcohol use, and I am planning to use simulations based on a hurdle model (using the hurdle() function in package pscl) for sample size estimation. The simulation code and power code are below -- note that at the moment the "power" code is just returning the coefficients, as something isn't working quite right. The
2010 Aug 18
1
Displaying Results in Two Columns
Could I have some suggestions as to how (various ways) I can display my confidence interval results? rm(list = ls()) set.seed(1) func <- function(d,t,beta,lambda,alpha,p.gamma,delta,B){ d <- c(5,1,5,14,3,19,1,1,4,22) t <- c(94.32,15.72,62.88,125.76,5.24,31.44,1.048,1.048,2.096,10.48) post <- matrix(0, nrow = 11, ncol = B) theta <- c(lambda,beta) beta.hat <- 2.471546 for(j
2011 Nov 10
1
Gibbs sampler
I have the following code, gibbs <-function(m,theta = 0.25, lambda =0.55, n =1){ alpha <- 1.5 beta <- 1.5 gamma <- 1.5 x<- array(0,c(m+1, 3)) x[1,1] <- theta x[1,2] <- lambda x[1,3]<- n for(t in 2:(m+1)){ x[t,1] <- rbinom(1, x[t-1,3], x[t-1,1]) x[t,2]<-rbeta(1, x[t-1,1] + alpha, x[t-1,3] - x[t-1,1] + beta) x[t,3]
2012 Feb 09
1
Constraint on one of parameters.
Dear all, I have a function to optimize for a set of parameters and want to set a constraint on only one parameter. Here is my function. What I want to do is estimate the parameters of a bivariate normal distribution where the correlation has to be between -1 and 1. Would you please advise how to revise it? ex=function(s,prob,theta1,theta,xa,xb,xc,xd,t,delta) { expo1=
2011 Nov 07
3
Correction in error
Hello R community, following is my code and it shows error, can some one fix this error and explain why this occurs? gibbs <-function(m,n, theta = 0, lambda = 1){ alpha <- 1.5 beta <- 1.5 gamma <- 1.5 x<- array(0,c(m+1, 3)) x[1,1] <- theta x[1,2] <- lambda x[1,3]<- n for(t in 2:m+1){ x[t,1] <- rbinom(x[t-1,3], 1, x[t-1,1])
2009 Aug 17
2
Newbie that don't understand R code
I got some R code that I don't understand. Question as comment in code //where is t comming from, what is phi inverse rAC <- function(name, n, d, theta){ #generic function for Archimedean copula simulation illegalpar <- switch(name, clayton = (theta < 0), gumbel = (theta < 1), frank = (theta < 0), BB9 = ((theta[1] < 1) | (theta[2] < 0)), GIG = ((theta[2] < 0) |
2009 May 19
2
what is wrong with this code?
dlogl <- -(n/theta)-sum((y/(theta)^2)*((1-exp(y/theta))/(1+exp(y/theta))) d2logl <- (n/theta^2) - sum((-2y/theta^3)*(1-exp(y/theta))/(1+exp(y/theta))) - sum(((2*y/theta^4)*exp(y/theta))/((1+exp(y/theta))^2)) returns the error message: Error: unexpected symbol in: "dlogl <- -(n/theta)-sum((y/(theta)^2)*((1-exp(y/theta))/(1+exp(y/theta))) d2logl" do you know what i have done
2012 Apr 30
2
Using GEE with sample weights
Dear R community I am using the gee package to run logistics regression on paired cases from a panel sample. We are getting request from a reviewer to use sample weights to account for different level of attrition. After searching the documentation I am unable to find a way to incorporate sample weights into the gee formula. I found a way to incorporate precision weight but I understand that I
2008 Apr 22
2
optimization setup
Hi, here comes my problem, say I have the following functions (example case) #------------------------------------------------------------ function1 <- function (x, theta) {a <- theta[1] ( 1 - exp(-theta[2]) ) * theta[3] ) b <- x * theta[1] / theta[3]^2 return( list( a = a, b = b )) } #----------------------------------------------------------- function2<-function (x, theta) {P
2008 Mar 19
1
problem with optim and integrate
Dear all, I want to min "integrate( (p1*dnorm+p2*dnorm+p3*dnorm)^(1.3))" for p, mu, and sigma. So, I have to estimate 8 parameters(p3=1-p1-p2). I got this warning-"Error in integrate(numint, lower = -Inf, upper = Inf) : non-finite function value." My questions are How could I fix it? I tried to divide into several intervals and sum up, but I got same message. My code is
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