0

The question is similar to the one in the following post:

" troubles converting proc nlmixed (SAS) to nlme (R) "

Community
  • 1
  • 1
goren9
  • 19
  • 1
  • 6
  • What R code have you attempted? – Thomas Oct 31 '14 at 08:53
  • Useful edit would be to create a sample data set in SAS, run your analysis (no more than 20 records, say), show the results, and then we'd know what the target we were shooting for was (especially if you give us the sample data set too). In my experience very few ppl here have SAS licenses compared to R licenses... – Spacedman Oct 31 '14 at 13:28

1 Answers1

2

This doesn't look like a mixed model at all -- what is the random effect? It looks like a slightly unusual generalized linear model: I would think this would do it.

glm((1-p)~d1+d2+d3+d4-1,family=binomial(link="log"))

(you'll have to flip the sign of the parameters yourself).

Tiwari et al. 2006 fit a model of this type.

R equivalent:

dd <- read.table("sas_vals.txt",header=TRUE,na.string=".")
g1 <- glm((1-Y)~d1+d2+d3+d4-1,family=binomial(link="log"),data=dd,
    start=rep(-0.1,4))

This is a bit difficult, probably in part because of the tiny data set (I assume this is a subset of the real data -- fitting 4 parameters to 21 binary observations would be a very bad idea ...)

Or:

library("bbmle")
g2 <- mle2(Y~dbinom(prob=1-exp(-p),size=1),
           parameters=list(p~d1+d2+d3+d4-1),
           start=list(p=0.1),
           data=dd)

The log-likelihoods suggest that the mle2 fit is better, and refitting the glm fit with those starting values works better:

g3 <- update(g1,start=-coef(g2))
g4 <- mle2(Y~dbinom(prob=1-(exp(-p)^exp(b*Treat)),size=1),
           parameters=list(p~d1+d2+d3+d4-1),
           start=list(p=0.1,b=0),
           data=dd)
summary(g4)
##      Estimate Std. Error z value  Pr(z)
## p.d1 0.106163   0.088805  1.1955 0.2319
## p.d2 0.241029   0.178263  1.3521 0.1763
## p.d3 0.105970   0.113455  0.9340 0.3503
## p.d4 0.179232   0.189951  0.9436 0.3454
## b    0.559624   0.740500  0.7557 0.4498

This seems to match the SAS results pretty well.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • that's harder -- I think you won't easily find an R package that allows for generalized nonlinear mixed models. You might have to go to a system like AD Model Builder. You could ask as a separate question, or ask on `r-sig-mixed-models@r-project.org` ... – Ben Bolker Nov 05 '14 at 12:03