You are on page 1of 2

HW4 - Problem 6.2.

Man-fang Liang

2023-05-05

Data

dat.signal=c(3,7,14,24,32,12)
dat.noise=c(12,16,21,15,10,6)

General Multinomial Model

NS=sum(dat.signal)
NN=sum(dat.noise)
parest.signal=dat.signal/NS
parest.noise=dat.noise/NN

#negative log likelihood for one stimulus


nll.mult.1=function(p,y) -sum(y*log(p))
#negative log likelihood for two stimulus
nll.general=nll.mult.1(parest.signal,dat.signal)+nll.mult.1(parest.noise, dat.noise)
nll.general

## [1] 283.1945

Signal Detection Model

# helper function that computes the value of p.ij for any mean.j, sd.j and vector of bounds
sd.prob.1=function(mean,sd,bounds)
{
cumulative=c(0,pnorm(bounds,mean,sd),1)
p.ij=diff(cumulative)
return(p.ij)
}

#negative log likelihood of free-variance signal detection


#for confidence interval paradigm
#par=d,sigma,bounds

1
#y=y_(1,s),..,y_(I,s),y_(1,n),..,y_(I,n)
nll.sigdet=function(par,y)
{
I=length(y)/2
d=par[1]
sigma=par[2]
bounds=par[3:length(par)]
p.noise=sd.prob.1(0,1,bounds)
p.signal=sd.prob.1(d,sigma,bounds)
nll.signal=nll.mult.1(p.signal,y[1:I])
nll.noise=nll.mult.1(p.noise,y[(I+1):(2*I)])
return(nll.signal+nll.noise)
}

sigdet <- optim(nll.sigdet, par=c(1, 1, -1, 0, 1, 2, 3), y=c(dat.signal, dat.noise),control=list(maxit=1

sigdet

## $par
## [1] 0.6933274 0.8410482 -0.9832706 -0.3793114 0.2078974 0.7772900 1.5834454
##
## $value
## [1] 284.6423
##
## $counts
## function gradient
## 838 NA
##
## $convergence
## [1] 0
##
## $message
## NULL

Likelihood Ratio Test


G-squared

2 * (sigdet$value - nll.general)

## [1] 2.895623

# critical value of the chi-square statistic


critical.val <- qchisq(0.95, 10-7)
critical.val

## [1] 7.814728

𝐺2 is 2.90, less than the critical value of 7.81 with 3 degrees of freedom. The free-variance signal detection
model is also appropriate for the data.

You might also like