Question: attach ( L ) L < - as . data.frame ( L ) #Likelihood function logL < - function ( b , X , Y

attach(L)
L <- as.data.frame(L)
#Likelihood function
logL <- function(b,X,Y){
b0}<-\textrm{b}[1
b1<- b[2]
logn <- sum((log( exp(b0+b1X))))(log(1-exp(b0+b1X))))) #Likelihood
return (-logn)
}
#optimization to get ML parameters
pm2L <- optim(c(2,-1),logL,Y=LY,x=LX,hessian=TRUE)
#compute marginal effect
probhat <- exp(pm2Lpar[1]+pm2Lpar[2]*Lxpar[1]+pm2Lpar[2]*LX))
dFdxL <- mean((probhat*(1-probhat))*pm2L$par[2])
#check whether identical to starting point of our analytical calculations last week:
1/100*sum(pm2Lpar[1]-pm2Lpar[2]*LX))^(-2)*exp(-pm2Lpar[1]-pm2Lpar[2]*L$X)) #relevant element of Jacobian
J1<-1/100pm2L$par[2]*L
J <-1/100*sum((exp(-pm2Lpar[1]-pm2Lpar[2]*Lxpar[1]-pm2Lpar[2]*LX))+pm2L
#multiply Jacobian by variance covariance matrix,
sqrt(matrix(c(J1,J), nrow=1,ncol=2)%%matrix(c(J1,J), nrow=2,ncol=1))
tstat<- dFdxL/sqrt(matrix(c(J1,J), nrow=1,ncol=2)%%matrix(c(J1,J), nrow=2,ncol=1))
2*(1-pnorm(abs(tstat)))stddFdxL <- abs(J)*sqrt(diag(solve(pm2L$hessian))[2])
#derive z-statistic (marginal effect divided by sandard deviation of marginal effect)
dFdxL/stddFdxL; tdFdxL <- dFdxL/stddFdxL
#compute p-value corresponding to size of that test statistic. (know that the test statistic is asymptotically
2*(1-pnorm(abs(tdFdxL)))
#check computations with built-in command.
#marginal effect:
library(VGAM)
a <- glm(Y~X, family = binomial(link = "logit"), data=L)#know that distribution of Y is equal to a binomial dist
summary(a)library(mfx)
logitmfx(Y~X, data=L, atmean=FALSE)
#slight differences in betahats, coefficients & marginal effects lead to different standard errors via delta meA <- read.table("/Documents/Daten R/Microeconometrics/Logit.csv",header=TRUE,sep=";")
attach(A)
A <- as.data.frame(A)
#programme probit function
probit <- function(theta,X,Y){beta1<- theta[2]linpred <- beta0+beta1*Xcolnames(results)<-c("b","se","t","p")
rownames(results)<-c("Constant","X1")
print(results,digits=3)
library(VGAM)
a <- glm(Y~X, family = binomial(link = "probit"),data=A)
summary(a)mean(dnorm(pm2par[1]+pm2par[2]*X)*pm2par[2]);dFdx <-mean(dnorm(pm2par[1]+pm2par[2]**X)**pm2par[2])
1ibrary(VGAM)
library(mfx)# look at the documentation of the package.
library(ProbMarg)
a <- glm(Y~X, family = binomial(link = "probit"),data=A)
#margeff(a)
probitmfx(Y~X,data=A, atmean=FALSE)
mean(margEffects (a,method="probit",specs=A)[,1])
summary(pnorm(pm2par[1]+pm2par[2]*X))
mean (pnorm(pm2par[1]+pm2par[2]*X)) #compute significance of marginal effect via delta rule
J <-1/100*(sum(dnorm(pm2par[1]+pm2par[2](-pm2par[1]-pm2par[2]*X)pm2par[1]+pm2$par
stddFdx <- abs(J)*sqrt(diag(solve(pm2$hessian))[2])
dFdx/stddFdx; tdFdx <- dFdx/stddFdx
2*(1-pnorm(abs(tdFdx)))hatPY <- pnorm(pm2par[1]+pm2par[2]*X)
hatY <- ifelse(hatPY>=0.5,1,0)
TRUEFP <- ifelse(hatY==Y,1,0)
CountR2<- sum(TRUEFP)/length(Y)
use similar r codes like this for the above question

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!