Created
October 3, 2014 11:25
-
-
Save Benjit87/a3acaaa3eb20a08bd560 to your computer and use it in GitHub Desktop.
Enhancing SAP PA Summary for Custom R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Create your own S class, pass your results as object, use your own summary function | |
Summary_Printer <- function(obj1) UseMethod("Summary_Printer") | |
Summary_Printer.default <- function(regression,sandwich) | |
{ | |
printer <- NULL | |
printer$regression <- regression | |
printer$sandwich <- sandwich | |
class(printer) <- "Summary_Printer" | |
printer | |
} | |
#Your own summary function of the Summary_Printer Class | |
#This will be output as summary in PA | |
summary.Summary_Printer <- function(printer) | |
{ | |
summary(printer$regression) | |
print("**** SANDWICH ESTIMATOR ***\n") | |
print(printer$sandwich) | |
} | |
REG_SANDWICH <- function(data,x,y) | |
{ | |
formattedString<-paste(x,collapse='+') | |
formatedString <- as.formula(paste(paste(y," ~ ",collapse=""),formattedString,collapse="")) | |
results <- lm(formatedString,data) | |
df <- data.frame(results$coefficients) | |
df <- cbind(row.names(df),df) | |
#Visualisation | |
par(mfrow=c(2,2)) | |
plot(results) | |
plot(results) | |
plot(results) | |
plot(results) | |
sandwich_test <- bptest(results,studentize=FALSE) | |
results1 <- Summary_Printer(results) | |
return(list(out=df, model=results1)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment