Hi all this is the data and I have generated codes although I don't know if they are correct. I am looking for a conversation and details to see if I am on the right path.

set.seed(nchar(first_name)+nchar(last_name))

n.pop<-10000

subscribe<-sample(c(1,0),n.pop,replace=TRUE,prob=c(0.5,0.5))

pb1<-sample(65:75,1)/100

pb2<-0.5

ad.l1<-0.0

ad.l2<-sample(10:20,1)/100

ap1<-sample(65:75,1)/100

ap2<-0.5

set.seed(nchar(last_name))

see.ad.random<-runif(n.pop)

see.ad<-ifelse(subscribe,1*(see.ad.random<ap1),1*(see.ad.random<ap2))

buy.random<-runif(n.pop)

buy.thres1<-pb1+ad.l1*see.ad
buy.thres2<-pb2+ad.l2*see.ad

buy<-ifelse(subscribe,1*(buy.random<buy.thres1),1*(buy.random<buy.thres2))

data<-cbind.data.frame(subscribe,see.ad,buy)

rm(list = ls(pattern="[^data,first_name,last_name]"))

##############################################

#2. calculate the weights. Put results in "result2".

# Length of the vector "result2" should be the same as the number of rows in data.

wghtmodel<-glm( formula= see.ad ~ buy * subscribe, family="binomial", data=data)

wght_df <- data.frame(wghtscr = predict(wghtmodel, type = "response"),

subscribe = wghtmodel$model$subscribe)

result2 <- wght_df