TMLE issue:
Closed this issue · 1 comments
Hello, I am using the R-packages, SuperLearner and TMLE. I have post the specific code below that results in the error. I have also posted the full code below. The TMLE call does not require the argument "new data" so I am confused what the issue is.
fit <- tmle(Y=Y, A=NULL, Delta=Tmat[,1], W=W,
Q=Qtmat[,c(start,end)],
g.SL.library=SL.library,family="gaussian", verbose=TRUE)
I get the following error:
Error in object$fit$predict(newdata, offset) :
argument "newdata" is missing, with no default
###Load tmle Package and Specify Super Learner Library###
#-------------------------------------------------------#
install.packages("randomForest")
install.packages("nnet")
install.packages("gam")
install.packages("dbarts")
library(tmle); library(SuperLearner); library(tidyverse); library(foreign); library(readstata13); library(glmnet);library(randomForest);library(nnet);library(gam);
library(dbarts)
#Create a unique wrapper function for ridge to use in library
SL.glmnet0 <- create.Learner("SL.glmnet", detailed_names = T,
tune=list(alpha = 0))
SL.library <- list("SL.glm", SL.glmnet0$names, "SL.rpart")
LOAD CSV DATA (FROM TMLE FOLDER ON DESKTOP -- THIS IS FILE I EXTRACTED FROM SAS. IT WAS CLEANED IN SAS THEREFORE NO MISSING VARIABLES)
TMData = read_csv("finaldatanew1.csv")
TMData = mutate(TMData, popden0 = ifelse(popdensity2==0, 1, 0))
TMData = mutate(TMData, popden1 = ifelse(popdensity2==1, 1, 0))
TMData = mutate(TMData, popden2 = ifelse(popdensity2==2, 1, 0))
TMData = mutate(TMData, popden3 = ifelse(popdensity2==3, 1, 0))
state <- substr(TMData$FIPS,1,2)
state = data.frame(state)
TMData <- data.frame(cbind(TMData,state))
#---------------------------------------------------------#
###Load Simulation Data and True Population Level Values###
#---------------------------------------------------------#
set.seed(27)
W <- TMData %>% select(income, white, broadband, beds1, cmhc1, chc1, mdaprn1, cases1, pre1new1, pre2new1)
Tmat <- TMData %>% select(popden0, popden1, popden2, popden3)
Xmat<-as.data.frame(cbind(W,Tmat[,1:4]))
state <-TMData$state
Y<-TMData$out2
K<-dim(Tmat)[2];
n<-dim(TMData)[1];
S<-length(unique(state))
#---------------------------------------------#
###Create Counterfactual Treatment Scenarios###
#---------------------------------------------#
Xmat0<-transform(Xmat, popden0=1, popden1=0, popden2=0, popden3=0)
Xmat1<-transform(Xmat, popden0=0, popden1=1, popden2=0, popden3=0)
Xmat2<-transform(Xmat, popden0=0, popden1=0, popden2=1, popden3=0)
Xmat3<-transform(Xmat, popden0=0, popden1=0, popden2=0, popden3=1)
Xmatnew<-as.data.frame(rbind(Xmat0,Xmat1,Xmat2,Xmat3))
#-------------------------------------------------------------------------------------------#
###Run Super Learner Once, Obtain Initial Predicted Values for All Counterfactual Settings###
#-------------------------------------------------------------------------------------------#
#Step 1: Estimating the outcome regression using super learner
SL.fitnew <- SuperLearner(Y=Y, X=Xmat, newX=Xmatnew, SL.library=SL.library,
family=gaussian(),method="method.NNLS", verbose=TRUE)
Q0<-rep(0,nK); Qtvector<-cbind(Q0,SL.fitnew$SL.predict)
Qtmat<-matrix(unlist(split(as.data.frame(Qtvector), rep(1:K, each = n))), ncol=2K)
#-----------------------------------------------------------------------------------#
###Run TMLE to Calculate Point Estimates of each T=t with Custom Cluster-Based SEs###
#-----------------------------------------------------------------------------------#
#Steps 2-5 are performed in this code chunk#
popden_results<-matrix(NA, nrow=K, ncol=4)
rownames(popden_results)<-colnames(Tmat);colnames(popden_results)<-c("EYt","SE","CI1","CI2")
start<-1;end<-2;gbound<-0.025
fit <- tmle(Y=Y, A=NULL, Delta=Tmat[,1], W=W,
Q=Qtmat[,c(start,end)],
g.SL.library=SL.library,family="gaussian", verbose=TRUE)
Hi, this repository is not the right place to ask R questions, it was a repository gathering ideas for a hackathon.
Here's some guidance on asking for help with R
Good luck!