Displaying 20 results from an estimated 4000 matches similar to: "what is wrong with this code?"
2009 May 15
4
displaying results
Hi everyone, can anyone tell me how i can change how i display mean(age), i
want it to say The mean age of patients within the sample is mean(age)
--
View this message in context: http://www.nabble.com/displaying-results-tp23558890p23558890.html
Sent from the R help mailing list archive at Nabble.com.
2009 Aug 17
2
help with expression()
Hello.
I have a vector and within that vector is one expression. When I display
this vector it comes up as
expression(NA_character_, NA_character_, "Null Effect", "Pooled effect",
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, paste("Het Contours ", I^2, sep = ""), 0.4,
0.41, 0.42, 0.45, NA_character_)
Where the
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=
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) |
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
2005 Mar 16
1
Code to replace nested for loops
Dear list members,
How can I replace the nested for loops at then end of the script
below with more efficient code?
# Begin script__________________________________________________
# Dichotomous scores for 100 respondents on 3 items with
# probabilities of a correct response = .6, .4, and .7,
# respectively
x1 <- rbinom(100,1,.6)
x2 <- rbinom(100,1,.4)
x3 <- rbinom(100,1,.7)
#
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
2009 Aug 17
2
unnecessary braces?
the version 2 parser thinks I have unnecessary braces,
but I can't find any. False positive or am I missing
something? If a false positive, is there any way to
work around the warning?
* checking Rd files against version 2 parser ... WARNING
Warning: ./man/dbetabinom.Rd:32-34: Unnecessary braces at ?{p(x) = %
(C(N,x)*Beta(N-x+theta*(1-p),x+theta*p))/%
Beta(theta*(1-p),theta*p)}?
2008 Dec 27
1
indexed expression
Hello expeRts,
I need generate symbolize the autocovariances matrix of a Gaussian
ARMA(1,1), for derivate it and evaluate.
I try this codes, but whitout sucess
vacv<-NULL
vacv[1]<-1-2*phi*theta-theta^2
vacv[2]<-(1-phi*theta)*(phi-theta)
vacv[3:n]<-acv[2]*(phi^(1:(n-2)))
facv<-list()
for(i in 1:2)
2005 May 31
1
Solved: linear regression example using MLE using optim()
Thanks to Gabor for setting me right. My code is as follows. I found
it useful for learning optim(), and you might find it similarly
useful. I will be most grateful if you can guide me on how to do this
better. Should one be using optim() or stats4::mle?
set.seed(101) # For replicability
# Setup problem
X <- cbind(1, runif(100))
theta.true <- c(2,3,1)
y <- X
2011 Aug 17
2
An example of very slow computation
This message is about a curious difference in timing between two ways of computing the
same function. One uses expm, so is expected to be a bit slower, but "a bit" turned out to
be a factor of >1000. The code is below. We would be grateful if anyone can point out any
egregious bad practice in our code, or enlighten us on why one approach is so much slower
than the other. The problem
2006 Jul 25
5
greek letters, text, and values in labels
Hello,
I want to have a title that will look something like:
"Results for \theta=2.1", given that I have a variable theta=2.1, and
\theta should show on the screen like the greek letter.
I've tried a lot of things:
theta <- 2.1
plot(1:10, main=expression(paste("Results for", theta, "=", eval(theta))))
or using bquote
plot(1:10, main=paste("Results for
2009 Nov 08
3
MCMC gradually slows down
Hello,
I have written a simple Metropolis-Hastings MCMC algorithm for a
binomial parameter:
MHastings = function(n,p0,d){
theta = c()
theta[1] = p0
t =1
while(t<=n){
phi = log(theta[t]/(1-theta[t]))
phisim = phi + rnorm(1,0,d)
thetasim = exp(phisim)/(1+exp(phisim))
r = (thetasim)^4*(1-thetasim)^8/(theta[t]^4*(1-theta[t])^8)
if(runif(1,0,1)<r){
theta[t+1] = thetasim
}
2014 Mar 03
1
reference classes, LAZY_DUPLICATE_OK, and external pointers
We (the lme4 authors) are having a problem with doing a proper deep
copy of a reference class object in recent versions of R-devel with
the LAZY_DUPLICATE_OK flag in src/main/bind.c enabled.
Apologies in advance for any improper terminology.
TL;DR Is there an elegant way to force non-lazy/deep copying in our
case? Is anyone else using reference classes with a field that is an
external pointer?
2012 Dec 04
1
Solve system of equations (nleqslv) only returns origin
I'm solving 4 complex equations simultaneously. Code is below. The code
returns only zero's for the solution though there should also be a non-zero
result. I'm pretty confident that the equations are correct because they
are straight from a published paper and I checked them pretty thoroughly.
The parameter values I used are from the published paper as well. Any
suggestions for how
2006 Apr 05
2
R2WinBUGS error
Dear R-help,
I'm using the R2WinBUGS package and getting an error message:
Error in file(file, "r") : unable to open connection
In addition: Warning message:
cannot open file 'codaIndex.txt', reason 'No such file or
directory'
I'm using R 2.2.1 and WinBUGS 1.4.1 on a windows machine (XP). My R code
and WinBUGS code is given below.
2009 Nov 02
2
a prolem with constrOptim
Hi,
I apologize for the long message but the problem I encountered can't be stated in a few lines.
I am having some problems with the function constrOptim. My goal is to maximize the likelihood of product of K multinomials, each with four catagories under linear constraints on the parameter values. I have found that the function does not work for many data configurations.
#The likelihood
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
2006 Sep 30
1
Gradient problem in nlm
Hello everyone!
I am having some trouble supplying the gradient function to nlm in R for
windows version 2.2.1.
What follows are the R-code I use:
fredcs39<-function(a1,b1,b2,x){return(a1+exp(b1+b2*x))}
loglikcs39<-function(theta,len){
value<-sum(mcs39[1:len]*fredcs39(theta[1],theta[2],theta[3],c(8:(7+len))) -
pcs39[1:len] * log(fredcs39(theta[1],theta[2],theta[3],c(8:(7+len)))))