plyr


Likelihood over subgroups


I saw many messages regarding the message error "arguments imply differing number of rows" but here it's slightly different. I would like to maximize a likelihood function, which includes cumulative products over subgroups. However at the end I get the message "arguments imply differing number of rows: 2, 413". I have 413 lines in my dataset. This message also comes when I do it with some random variables from my dataset.
Here is the code :
fcontriloglik = function(para){
S_t<<-NA ## I try to create a global variable
Define parameters :
betarisk1 = para[1:2]
sigmarisk1 = para[3:21]
Treat1 = para[22]
Compute parts of the likelihood :
Xb1 = x%*%betarisk1
Xsig1 = sigma%*%sigmarisk1
XbT1 = treatment*Treat1
exbTreat1 = exp(Xb1 + Xsig1 + XbT1)
Contributions :
h1 = 1 - exp(-exbTreat1)
S_t <<- (1 - h1)
I want to make a cumulative product over individuals :
datatest<-ddply(newdata, .(id), transform, cumSt=cumprod(S_t))
cumulativesum<-data.frame(datatest$cumSt)
Compute the likelihood :
l1 <- (h1/(1-h1))^risk * cumulativesum
loglik = log(l1)
return(l1)
}
Return the value of the likelihood with initial values I set at the beginning :
fcontriloglik(stval)
The error comes from "cumSt=cumprod(S_t)" which it is not able to compute.
Thanks a lot !

Related Links

Likelihood over subgroups
Error in Changing Factors with PLYR in R
Frequency table in R
Installation of plyr in R on Ubuntu does not work
Issue installing library(plyr) in R (Windows)

Categories

HOME
svn
verification
yahoo-weather-api
schema.org
postgresql-9.4
elk-stack
tibco
drag-and-drop
position
gprs
firebase-dynamic-links
static-analysis
tup
hspi
twitter-oauth
lapack
locationmanager
chromecast
spring-amqp
bnf
gravity
cloudsim
wsf
data-type-conversion
activeadmin
hdl
maven-surefire-plugin
device
web-push
hevc
basic-authentication
social-networking
amazon-iam
premake
delayed-job
apptentive
rails-postgresql
xvfb
code-rally
suds
jacoco-maven-plugin
distributed-caching
audio-converter
gcal
common-table-expression
ol3-google-maps
extjs4.1
pecl
zend-server
kendo-treeview
petsc
yargs
streamwriter
bilinear-interpolation
msbuild-4.0
mathml
highlighting
strpos
apple-configurator
exists
vaadin4spring
management-studio-express
myfaces
mousehover
knife
postal-code
swagger-maven-plugin
angular-amd
flow-js
shell-extensions
signed
mojo
directorysearcher
cout
producer
jini
spring-social-linkedin
strcmp
sly-scroller
html-frames
background-thread
xalan
msinfo32
websphere-6.1
sigar
haiku
getopts
qcar-sdk
dip
ios-4.2
ccnet-config
tabbarcontroller
raw-data
iphone-sdk-4.3
zend-test
jquery-effects
gtktextview
levels

Resources

Encrypt Message