search for: lik

Displaying 20 results from an estimated 187 matches for "lik".

Did you mean: like
2009 Jan 05
2
Sweave data-figure coupling
...With the following Sweave minimal file: ---<--------------------cut here---------------start------------------->--- \documentclass{article} \usepackage{Sweave} \begin{document} <<binom-sim>>= thetas <- seq(0, 1, by=0.001) prior <- rep(1, length(thetas)) / length(thetas) lik <- dbinom(1, 1, thetas) lik.p <- prior * lik post <- lik.p / sum(lik.p) <<binom-sim-fig, fig=TRUE, include=FALSE, height=3, echo=FALSE>>= layout(matrix(1:2, ncol=2)); par(mar=c(5, 4, 2, 1), cex=0.75) matplot(thetas, cbind(prior, lik, post), type="l", lty=c(2, 1, 1),...
2007 Oct 24
1
vectorized mle / optim
Hi the list, I would need some advice on something that looks like a FAQ: the possibility of providing vectors to optim() function. Here is a stupid and short example summarizing the problem: -------------------------------- example 1 ------------ 8< ---------------------- library(stats4) data <- rnorm(100,0,1) lik1 <- function(m, v, data) { N <...
2011 Mar 19
2
problem running a function
...ebook/panel4pt1.fn that applied to my data and in the console is as follows: > `desman.y` <- structure(c(3L,4L,3L,2L,1L), .Names = c("1", "2", "3", "4", > "5")) > > RN<-function(y=desman.y,J=5,nsites=39,Nmax=100){ + #### + lik<-function(parms){ + r<-expit(parms[1]) + lambda<-exp(parms[2]) + pvec<-1-(1-r)^(0:Nmax) + gN<-dpois(0:Nmax,lambda) + gN<-gN/sum(gN) + lik<-rep(NA,nsites) + for(i in 1:nsites){ + lik[i]<-sum(dbinom(y[i...
2010 Jul 22
1
function return
...ead.table("wtmatrix.txt",header=T,na.strings=T) elev<-data[,"elev"] forest<-data[,"forest"] elev<-scale(elev,center=TRUE) forest<-scale(forest,center=TRUE) pamat<-data[,c("y.1","y.2","y.3")] z<-pamat[,1] M<-length(z) lik<-function(parms){ b0<-parms[1] b1<-parms[2] b2<-parms[3] b3<-parms[4] ones<-rep(1,M) ### Compute binomial success probabilities probs<-expit(b0*ones+b1*elev+b2*(elev^2)+b3*forest) lik<-rep(0,length(z)) ### evaluate log of binomial...
2012 Aug 08
1
dimnames in array
...t;-`(`*tmp*`, value = c("V", "R")) : length of 'dimnames' [2] not equal to array extent" When I type in length(dimnames(data11a)[2]) I get the answer: [1] 1 which seems odd when dimnames(data11a)[2] gives [[1]] [1] "V" "R" I would like to ask "How can I get the names of the second dimension of the array(data11a) to have length "2" ? It seems to me that the analysis will run if I can make this array have the correct length dimnames I thank you for your help. ____________ * fd.data11a = data11a DEfd11a = Da...
2012 Apr 13
1
R: Colouring phylogenetic tip labels and/or edges
Hi, I have reconstructed ancestral character states on a phylogeny using MuSSE in the diversitree package and plotted the character state probabilities as pie charts on the nodes. I would, however, like to colour the character states of my extant species, i.e. the tip labels, the same colours as my pie charts, such that all species in state 1 are e.g. blue, species in state 2 red and species in state 3 yellow, and have not been successful with my attempts. I am only able to colour them in repea...
2006 Feb 07
1
sampling and nls formula
Hello, I am trying to bootstrap a function that extracts the log-likelihood value and the nls coefficients from an nls object. I want to sample my dataset (pdd) with replacement and for each sampled dataset, I want to run nls and output the nls coefficients and the log-likelihood value. Code: x<-c(1,2,3,4,5,6,7,8,9,10) y<-c(10,11,12,15,19,23,26,28,28,30) pdd...
2005 May 23
2
Documentation of S3 and S4 classes, inheritance
I'd like to have a class A that computes a likelihood, and a subclass B that computes the same likelihood by sometimes throws in an additional term (B includes measurement error). So B's likelihood needs to call A's, and then (sometimes) multiply by an additional term. It sounds as if, in the S3...
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] p<-Matrix(c(1, 0), nrow=1, ncol=2) Q<-Matrix(c(-(lambda1 + mu1), 0, lambda1, -mu2), nrow=2, ncol=2) q<-Matrix(c(mu1, mu2), nrow=2, ncol=1) for (i in 1:l...
2009 Feb 25
3
indexing model names for AICc table
hi folks, I'm trying to build a table that contains information about a series of General Linear Models in order to calculate Akaike weights and other measures to compare all models in the series. i have an issue with indexing models and extracting the information (loglikehood, AIC's, etc.) that I need to compile them into the table. Below is some sample code that illustrates my approach so far and my problem. I realize that somehow i need to provide actual object for the AIC or LogLik call, and I've tried a couple of different ideas (e.g., as.name, expr...
2005 Nov 11
1
optim not giving correct minima
Hello, I am trying to use optim() on a function involving a summation. My function basically is a thinned poisson likelihood. I have two parameters and in most cases optim() does a fine job of getting the minima. I am simulating my data based on pre specified parameters, so I know what I should be getting. However when my true parameters fall in a particular range, optim() gives incorrect results. I have g...
2012 Oct 20
4
Error in integrate(integrand, 0, Inf) : non-finite function value
...ector("numeric",length(1:2)) for (k in 1:2){ ll<-function(p){ cmh<-delta[,k]*(h[,k]*log(0.5))+p*log(gamma(1+1/p)) for(s in 1:10){ integrand<-function(x) x^d[s,k]*exp(-x*gamma(1+1/p))^p*p*x^(p-1)*exp(-x*h[s,k]) } integ<-integrate(integrand,0,Inf)$value cmhn<-as.vector(cmh) lik<-sum(cmhn+integ) -lik } initial<-c(1) t<-nlm(ll,initial) out[k]<-t$estimate } est<-as.vector(out) -- View this message in context: http://r.789695.n4.nabble.com/Error-in-integrate-integrand-0-Inf-non-finite-function-value-tp4646868.html Sent from the R help mailing list archive a...
2007 Nov 28
1
Power model in R
Um texto embutido e sem conjunto de caracteres especificado associado... Nome: n?o dispon?vel Url: https://stat.ethz.ch/pipermail/r-help/attachments/20071128/0d193362/attachment.pl
2009 Mar 23
0
Problems with adapt
...use of adapt. I'm new to R so I would appreciate any comment on my code below. Thanks Angelo ---------------------------------------------------------------------------------------------------------- DATA<-read.table("Data.csv",header=TRUE,sep=",") library(adapt) mnl.lik<-function(theta,y){ th1<-theta[1] th2<-theta[2] tha<-theta[3] thb<-theta[4] thc<-theta[5] thp<-theta[6] thmu<-theta[7] alfz1<-theta[8] alfz2<-theta[9] alfc<-theta[10] alf<-theta[11] r<- 1 s<- 1 n<-2000 lik<-numeric(n) int<-numeric(n) v<- numeric...
2012 Mar 14
1
Metropolis-Hastings in R
...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) alpha<-function(theta,phi) min(lik(phi)/lik(theta),1) theta1<-matrix(0,n,2) theta1[1,]<-mu for(i in 2:n){ theta<-theta1[i-1,] phi<-theta+runif(-0.5,0.5) k<-rbinom(1,1,alpha(theta,phi)) k1<-k1+k theta1[i,]<-theta+k*(phi-theta) }...
2011 May 23
6
Reading Data from mle into excel?
...ocuments/PhD/Swaption vols.csv" , header=TRUE, sep=",") X<-ts(vols[,2]) #X dcOU<-function(x,t,x0,theta,log=FALSE){ Ex<-theta[1]/theta[2]+(x0-theta[1]/theta[2])*exp(-theta[2]*t) Vx<-theta[3]^2*(1-exp(-2*theta[2]*t))/(2*theta[2]) dnorm(x,mean=Ex,sd=sqrt(Vx),log=log) } OU.lik<-function(theta1,theta2,theta3){ n<-length(X) dt<-deltat(X) -sum(dcOU(X[2:n],dt,X[1:(n-1)],c(theta1,theta2,theta3),log=TRUE)) } require(stats4) require(sde) set.seed(1) #X<-sde.sim(model="OU",theta=c(3,1,2),N=10000,delta=1) mle(OU.lik,start=list(theta1=1,theta2=1,theta3=1), m...
2010 Sep 30
3
how to avoid NaN in optim()
hi , lik <- function(nO, nA, nB, nAB){ loglik <- function(par) { p=par[1] q=par[2] r <- 1 - p - q if (c(p,q,r) > rep(0,3) && c(p,q,r) < rep(1,3) ) { -(2 * nO * log (r) + nA * log (p^2 + 2 * p * r) + nB * log (q^2 + 2 * q * r)...
2012 Oct 19
2
likelihood function involving integration, error in nlm
...2,1,0,0,1,1,0,1,2,2,1,0),nrow=10,ncol=2) h<-matrix(runif(20,0,1),10) integ<-matrix(c(0),nrow=10, ncol=2) ll<-function(p){ for (k in 1:2){ for(s in 1:10){ integrand<-function(x) x^d[s,k]*exp(-x*gamma(1+1/p))^p*p*x^(p-1)*exp(-x*h[s,k]) integ[s,k]<-integrate(integrand,0,Inf)$value } } lik<-colSums(integ) -lik } initial<-c(1) t<-nlm(ll,initial) Error in nlm(ll, initial) : invalid function value in 'nlm' optimizer Any suggestions will be greatly appreciated. Thank you in advance -- View this message in context: http://r.789695.n4.nabble.com/likelihood-function-...
2011 Nov 20
2
ltm: Simplified approach to bootstrapping 2PL-Models?
...red-expressed model fit-step") would be appropriate: GoF.ltm <- function(object, B = 50, ...){ liFits <- list() for(i in 1:B){ rndDat <- rmvlogis(nrow(object$X), coef(object)) liFits[[i]] <- ltm(rndDat ~ z1) } distr <- sort(sapply(liFits, function(x)return(x$log.Lik))) return(max(which(distr <= object$log.Lik))/length(distr)) } The rationale behind was to directly use the sorted sequence of (log)likelihoods of models fitted to 2PL-fitting-datasets where the parameters of <object> hold. The return value was intented to roughly mirror how many 2PL-Da...
2012 Aug 13
4
dimnames in an array(I'll be grateful if this message will be passed to all list users)
...<-rownames(data11, do.NULL = FALSE, prefix = "Obs.") colnames=c("V","R") varnames=c("one","two") dimnames(data11)<-list(rownames(data11), varnames, colnames) data11a<-as.array(data11, dimnames=dimnames(data11)) The analysis that I would like to do with R(CollocInfer) runs as follows(I print for the sake of introduction here though to run this line of code requires extensive setup) res11a = inneropt(coefs, times=times, data=data11a, lik=lik, proc=proc, pars=spars, in.meth='nlminb', control.in=control.out) The response I get...