Hi everybody! I am working on this project and have zero experience with R but I wanted to get advice from you all see what you all think about what I came up with

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.l1see.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

Error in data.frame(Treatment = c("See Ad", "Not See Ad"), Naive = c(0.5, :
object 'buyRateNoSeeAd' not found

Hi, it is because byyRateNoSeeAd doesn't exist anywhere. It helps if you post the error alongside your reproducible code. Can you also make the post titles more informative (describing the issue). You could the greeting within the post if you wanted to.

Hi thanks for the comment, I appreciate it. I have changed my post. How would you recommend that I fix part #4

buyRateNoSeeAd needs to be created somewhere. It isn't an object. You'll see that buyRateSeeAd is created in section #3.

so I think I had a spelling error that is why it was giving me an error. instead of putting the dollar sign $ I was putting the letter s

would you comment on my part two of the project?
It runs on my end but I am still not sure that is the correct code

#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

result2 is a dataframe rather than a vector. Going by the instructions it is incorrect.

so what if I name wght_df <- data.frame
result2 would that be ok?

Supposedly you're after a vector.

https://r4ds.had.co.nz/vectors.html

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.