People, I'm researching some Bayesian statistic topics and in the midle of my study i found a very simple problem and i'm trying to find a simple package to solve this type of equations: Lets say that i need to compute beta values for the beta distribution and i now for example: E(teta)=a/(a+b) = 0,5 Var(teta)=ab/((a+b)^2(a+b+1))=0.05 So if i want to solve this to non-linear system to find a,b for the beta distribution wich pack should i use? I know that a=2 and b=2 because i calculated it. Can someone help? Thanks, Eliano -- View this message in context: http://r.789695.n4.nabble.com/Solving-Equations-tp4318784p4318784.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
On Jan 22, 2012, at 1:25 PM, Eliano wrote:> People, > > I'm researching some Bayesian statistic topics and in the midle of > my study > i found a very simple problem and i'm trying to find a simple > package to > solve this type of equations: > > Lets say that i need to compute beta values for the beta > distribution and i > now for example: > > E(teta)=a/(a+b) = 0,5 > Var(teta)=ab/((a+b)^2(a+b+1))=0.05 > > So if i want to solve this to non-linear system to find a,b for the > beta > distribution wich pack should i use? > > I know that a=2 and b=2 because i calculated it.It depends on you meaning for the word "solve". If you want symbolic math, then the Ryacas package provides that facilities. If you want numerical estimation, then you should provide the data in your posting AND study the help pages for `nls` AND do searches in the Task Views AND the rhelp Archives for the wealth of worked examples available . -- David Winsemius, MD West Hartford, CT
On 22-01-2012, at 19:25, Eliano wrote:> People, > > I'm researching some Bayesian statistic topics and in the midle of my study > i found a very simple problem and i'm trying to find a simple package to > solve this type of equations: > > Lets say that i need to compute beta values for the beta distribution and i > now for example: > > E(teta)=a/(a+b) = 0,5 > Var(teta)=ab/((a+b)^2(a+b+1))=0.05 > > So if i want to solve this to non-linear system to find a,b for the beta > distribution wich pack should i use? > > I know that a=2 and b=2 because i calculated it. >There is a package nleqslv which can handle you system. library(nleqslv) eqf <- function(x) { a <- x[1] b <- x[2] y <- numeric(2) y[1] <- a/(a+b) - 0.5 y[2] <- a*b/((a+b)^2 * (a+b+1)) -0.05 y } x.start <- c(1,1) nleqslv(x.start,eqf) Berend
On Sun, Jan 22, 2012 at 1:25 PM, Eliano <eliano.m.marques at gmail.com> wrote:> People, > > I'm researching some Bayesian statistic topics and in the midle of my study > i found a very simple problem and i'm trying to find a simple package to > solve this type of equations: > > Lets say that i need to compute beta values for the beta distribution and i > now for example: > > E(teta)=a/(a+b) = 0,5 > Var(teta)=ab/((a+b)^2(a+b+1))=0.05 > > So if i want to solve this to non-linear system to find a,b for the beta > distribution wich pack should i use? >The equations giving a and b as a function of m and v are:> library(Ryacas) > a <- Sym("a"); b <- Sym("b") > m <- Sym("m"); v <- Sym("v") > Solve( List(a/(a+b) == m, a*b/((a+b)^2*(a+b+1)) == v), List(a, b) )expression(list(list(a == m^2 * (1 - m)/v - m, b == a/m - a))) Based on the above we write this R function: beta.parms <- function(m, v) { a <- m^2 * (1-m)/v - m b <- a/m - a c(a = a, b = b) } and run it:> beta.parms(m = 0.5, v = 0.05)a b 2 2 -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Like the t-shirt says, "There's no place like 127.0.0.1 " <quote> Though I wasn't familiar with this I check the repositories list and CRAN (extras) is selected in my installation (R-2.14.1). By the way, when trying Ryacas after what seemed to be a successful install, for a simple example of x <- 2 Eval(yacas(expression(x*x))) I got the following: [1] "Starting Yacas!" Error in socketConnection(host = "127.0.0.1", port = 9734, server = FALSE, : cannot open the connection In addition: Warning message: In socketConnection(host = "127.0.0.1", port = 9734, server = FALSE, : 127.0.0.1:9734 cannot be opened I tried adding yacas to my firewall exceptions but no help. David -- Sent from my Cray XK6 "Pendeo-navem mei anguillae plena est."