Thanks for the help (and letting me know about the homework policy). I will
refrain from using this for Homework purposes. I do have a project that I
am sure I will have to work the bugs out of later though. Thanks for the
advice.

On Tue, Nov 13, 2012 at 9:46 AM, David Winsemius [via R] <
ml-node+s789695n4649404h42@n4.nabble.com> wrote:

>
> On Nov 12, 2012, at 2:16 PM, jackle1o4 wrote:
>
> > Hello,
> > First time poster here so let me know if you need any more information.
> I am
> > trying to run an ordered probit with maximum likelihood model in R with
> a
> > very simple model (model <- econ3 ~ partyid). Everything looks ok until
> i
> > try to run the optim() command and that's when I get " Error in rep(1,
> > nrow(x)) : invalid 'times' argument". I had to adapt the code from a 4
> > category likelihood and I have a suspicion that the problem is in there.
> The
> > data set consists of two variables with 558 observations. Econ3 is a 1-3
> > rating and partyid is a range from -3(Strong Democrat) to 3 (Strong
> > Republican). Here is the code I used:
> >
> > setwd("C:/Users/Terry/Desktop/Terry/School/Fall 2012/ML/HW")
> >
> > #Load Libraries
> > library(MASS)
> > library(tile)
> > library(simcf)
> >
> > #Load Data
> > econrate <- read.csv("hw4econ3.csv", header=TRUE, sep=",")
>
> It's somewhat unusual to see a posting with an effort at posting code go
> uncommented for 18 hours, but in your case I suspect it is because people
> got to this point an were noticing the sprong resemblance to a homework
> assignment, which is discouraged on Rhelp. Speaking of a different sort of
> likelihood ... Help with assignments are not completely refused, but the
> chances of getting a reply would increase if you had indicated what
> academic institution you were studying at and what their policies are for
> soliciting help with academic assignments. Further increases in the
> likelihood of a response would occur if the h4econ3.csv file were made
> available at an URL or attached as a text file or included in the body of
> the message using the dput function.
>
>
> > attach(econrate)
>
> Generally a bad idea to attach() data objects, and that is especially so
> when you have not described the structure of the dataframe.
>
> >
> > #Ordered Probit Liklihood
> > llk.oprobit3 <- function(param, x, y) {
> > os <- rep(1, nrow(x))
> >  x <- cbind(os, x)
> >  b <- param[1:ncol(x)]
> >  t2 <- param[(ncol(x)+1)]
> > xb <- x%*%b
> >  p1 <- log(pnorm(-xb))
> >  if (t2<=0)  p2 <- -(abs(t2)*10000)
> > else p2 <- log(pnorm(t2-xb)-pnorm(-xb))
> >  p3 <- log(1-pnorm(t2-xb))
> > -sum(cbind(y==1,y==2,y==3) * cbind(p1,p2,p3))
> > }
> >
> > #Define Data
> > y <- econ3
> > x <- partyid
> > model <- (econ3 ~ partyid)
> >
> > #Use optim directly
> > ls.result <- lm(y~x)
> > stval <- c(ls.result$coefficients, 1)
> > oprobit.result <- optim(stval, llk.oprobit3, method="BFGS", x=x, y=y,
> > hessian=T) ###Here is where it all breaks down
> > pe <- oprobit.result$par
> > vc <- solve(oprobit.result$hessian)
> > se <- sqrt(diag(vc))
> > ll <- -oprobit.result$value
> >
> > Any help would be greatly appreciated. Thanks.
> >
> >
> >
> > --
> > View this message in context:
> http://r.789695.n4.nabble.com/Invalid-times-argument-three-category-ordered-probit-with-maximum-likelihood-tp4649341.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > [hidden email] <http://user/SendEmail.jtp?type=node&node=4649404&i=0>mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> David Winsemius, MD
> Alameda, CA, USA
>
> ______________________________________________
> [hidden email] <http://user/SendEmail.jtp?type=node&node=4649404&i=1>mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://r.789695.n4.nabble.com/Invalid-times-argument-three-category-ordered-probit-with-maximum-likelihood-tp4649341p4649404.html
>  To unsubscribe from Invalid 'times' argument three-category ordered
> probit with maximum likelihood, click here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4649341&code=dG1pY2thMkBnbWFpbC5jb218NDY0OTM0MXwzNDk2MjEzNDY=>
> .
> NAML<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://r.789695.n4.nabble.com/Invalid-times-argument-three-category-ordered-probit-with-maximum-likelihood-tp4649341p4649424.html
Sent from the R help mailing list archive at Nabble.com.
	[[alternative HTML version deleted]]


