Survival AFT Analysis with ScalaScala vs. Groovy vs. ClojureIs the Scala 2.8 collections library a case of “the longest suicide note in history”?Difference between object and class in ScalaWhat are all the uses of an underscore in Scala?Invalid survival times for distribution, Survival Analysis; package survivalRepresenting Parametric Survival Model in 'Counting Process' form in JAGScalculate p-value for AFT survival model in Sparkforecast time to event survival analysisCreat survival object with both right-cens and left-truncated + right-cens observationsDifferent results when presenting “From-To” data in survival analysis

Why has "pence" been used in this sentence, not "pences"?

Divine apple island

Proving a function is onto where f(x)=|x|.

Can I use my Chinese passport to enter China after I acquired another citizenship?

Should I install hardwood flooring or cabinets first?

When quoting, must I also copy hyphens used to divide words that continue on the next line?

Transformation of random variables and joint distributions

MAXDOP Settings for SQL Server 2014

Why did the EU agree to delay the Brexit deadline?

Can someone explain how this makes sense electrically?

Why does the integral domain "being trapped between a finite field extension" implies that it is a field?

My friend sent me a screenshot of a transaction hash, but when I search for it I find divergent data. What happened?

Journal losing indexing services

Varistor? Purpose and principle

What linear sensor for a keyboard?

Why in book's example is used 言葉(ことば) instead of 言語(げんご)?

Indicating multiple different modes of speech (fantasy language or telepathy)

Difference between -| and |- in TikZ

List of people who lose a child in תנ"ך

Have I saved too much for retirement so far?

Why do IPv6 unique local addresses have to have a /48 prefix?

How should I respond when I lied about my education and the company finds out through background check?

A Permanent Norse Presence in America

Is it possible to have a strip of cold climate in the middle of a planet?



Survival AFT Analysis with Scala


Scala vs. Groovy vs. ClojureIs the Scala 2.8 collections library a case of “the longest suicide note in history”?Difference between object and class in ScalaWhat are all the uses of an underscore in Scala?Invalid survival times for distribution, Survival Analysis; package survivalRepresenting Parametric Survival Model in 'Counting Process' form in JAGScalculate p-value for AFT survival model in Sparkforecast time to event survival analysisCreat survival object with both right-cens and left-truncated + right-cens observationsDifferent results when presenting “From-To” data in survival analysis













2















I am trying to implement the survival analysis model as documented here: Scala-Docs#Survival-Regression but I cannot make heads or tails of how you are supposed to do the actual implementation.



I am trying to model the "survivability" of a customer for a business. Survivability of a customer is a label given to customers based on if a purchase was made in the last month. If a customer fails to make a purchase, they are considered dead/censured. The two factors I am taking into account are "number of times advertised to" and "amount of time spent on business website". Data is collected about the customer on a monthly basis.



Here is what my data looks like for two customers (CustA and CustB) over three monthly time periods:



val seqCust = Seq(
//Customer,Period,Censor,# of Ads,Amount of Time on Site
("CustA",1,0,4,2400),
("CustA",2,0,6,1800),
("CustA",3,1,2,600),
("CustB",1,0,2,2800),
("CustB",2,0,4,2100),
("CustB",3,0,3,1200)
)


I then want to transform it into something like this as the docs specify:



val dfCust = seqCust.map(cr=>(cr._2,cr._3,Vectors.dense(cr._4,cr._5)).toDF("label", "censor", "features")


So that my data now looks like this:



[1,0,[4,2400]],
[2,0,[6,1800]],
[3,1,[2,600]],
[1,0,[2,2800]],
[2,0,[4,2100]],
[3,0,[3,1200]]


And then do the following:



val quantileProbabilities = Array(0.3, 0.6)
val aft = new AFTSurvivalRegression()
.setQuantileProbabilities(quantileProbabilities)
.setQuantilesCol("quantiles")

val model = aft.fit(dfCust)

// Print the coefficients, intercept and scale parameter for AFT survival regression
println(s"Coefficients: $model.coefficients")
println(s"Intercept: $model.intercept")
println(s"Scale: $model.scale")
model.transform(dfCust).show(false)


But I do not understand:



  1. Is this the correct way to model the data as per Scala's documentation?

  2. How come I am not taking the customer ID into account anywhere?









share|improve this question
























  • I'm not sure about your first question, it isn't clear for me. As per your second question, the default label, censor and features columns are respectively "label", "censor" and "features". That's why you didn't need to precise that explicitly.

    – eliasah
    Mar 21 at 9:30
















2















I am trying to implement the survival analysis model as documented here: Scala-Docs#Survival-Regression but I cannot make heads or tails of how you are supposed to do the actual implementation.



I am trying to model the "survivability" of a customer for a business. Survivability of a customer is a label given to customers based on if a purchase was made in the last month. If a customer fails to make a purchase, they are considered dead/censured. The two factors I am taking into account are "number of times advertised to" and "amount of time spent on business website". Data is collected about the customer on a monthly basis.



Here is what my data looks like for two customers (CustA and CustB) over three monthly time periods:



val seqCust = Seq(
//Customer,Period,Censor,# of Ads,Amount of Time on Site
("CustA",1,0,4,2400),
("CustA",2,0,6,1800),
("CustA",3,1,2,600),
("CustB",1,0,2,2800),
("CustB",2,0,4,2100),
("CustB",3,0,3,1200)
)


I then want to transform it into something like this as the docs specify:



val dfCust = seqCust.map(cr=>(cr._2,cr._3,Vectors.dense(cr._4,cr._5)).toDF("label", "censor", "features")


So that my data now looks like this:



[1,0,[4,2400]],
[2,0,[6,1800]],
[3,1,[2,600]],
[1,0,[2,2800]],
[2,0,[4,2100]],
[3,0,[3,1200]]


And then do the following:



val quantileProbabilities = Array(0.3, 0.6)
val aft = new AFTSurvivalRegression()
.setQuantileProbabilities(quantileProbabilities)
.setQuantilesCol("quantiles")

val model = aft.fit(dfCust)

// Print the coefficients, intercept and scale parameter for AFT survival regression
println(s"Coefficients: $model.coefficients")
println(s"Intercept: $model.intercept")
println(s"Scale: $model.scale")
model.transform(dfCust).show(false)


But I do not understand:



  1. Is this the correct way to model the data as per Scala's documentation?

  2. How come I am not taking the customer ID into account anywhere?









share|improve this question
























  • I'm not sure about your first question, it isn't clear for me. As per your second question, the default label, censor and features columns are respectively "label", "censor" and "features". That's why you didn't need to precise that explicitly.

    – eliasah
    Mar 21 at 9:30














2












2








2








I am trying to implement the survival analysis model as documented here: Scala-Docs#Survival-Regression but I cannot make heads or tails of how you are supposed to do the actual implementation.



I am trying to model the "survivability" of a customer for a business. Survivability of a customer is a label given to customers based on if a purchase was made in the last month. If a customer fails to make a purchase, they are considered dead/censured. The two factors I am taking into account are "number of times advertised to" and "amount of time spent on business website". Data is collected about the customer on a monthly basis.



Here is what my data looks like for two customers (CustA and CustB) over three monthly time periods:



val seqCust = Seq(
//Customer,Period,Censor,# of Ads,Amount of Time on Site
("CustA",1,0,4,2400),
("CustA",2,0,6,1800),
("CustA",3,1,2,600),
("CustB",1,0,2,2800),
("CustB",2,0,4,2100),
("CustB",3,0,3,1200)
)


I then want to transform it into something like this as the docs specify:



val dfCust = seqCust.map(cr=>(cr._2,cr._3,Vectors.dense(cr._4,cr._5)).toDF("label", "censor", "features")


So that my data now looks like this:



[1,0,[4,2400]],
[2,0,[6,1800]],
[3,1,[2,600]],
[1,0,[2,2800]],
[2,0,[4,2100]],
[3,0,[3,1200]]


And then do the following:



val quantileProbabilities = Array(0.3, 0.6)
val aft = new AFTSurvivalRegression()
.setQuantileProbabilities(quantileProbabilities)
.setQuantilesCol("quantiles")

val model = aft.fit(dfCust)

// Print the coefficients, intercept and scale parameter for AFT survival regression
println(s"Coefficients: $model.coefficients")
println(s"Intercept: $model.intercept")
println(s"Scale: $model.scale")
model.transform(dfCust).show(false)


But I do not understand:



  1. Is this the correct way to model the data as per Scala's documentation?

  2. How come I am not taking the customer ID into account anywhere?









share|improve this question
















I am trying to implement the survival analysis model as documented here: Scala-Docs#Survival-Regression but I cannot make heads or tails of how you are supposed to do the actual implementation.



I am trying to model the "survivability" of a customer for a business. Survivability of a customer is a label given to customers based on if a purchase was made in the last month. If a customer fails to make a purchase, they are considered dead/censured. The two factors I am taking into account are "number of times advertised to" and "amount of time spent on business website". Data is collected about the customer on a monthly basis.



Here is what my data looks like for two customers (CustA and CustB) over three monthly time periods:



val seqCust = Seq(
//Customer,Period,Censor,# of Ads,Amount of Time on Site
("CustA",1,0,4,2400),
("CustA",2,0,6,1800),
("CustA",3,1,2,600),
("CustB",1,0,2,2800),
("CustB",2,0,4,2100),
("CustB",3,0,3,1200)
)


I then want to transform it into something like this as the docs specify:



val dfCust = seqCust.map(cr=>(cr._2,cr._3,Vectors.dense(cr._4,cr._5)).toDF("label", "censor", "features")


So that my data now looks like this:



[1,0,[4,2400]],
[2,0,[6,1800]],
[3,1,[2,600]],
[1,0,[2,2800]],
[2,0,[4,2100]],
[3,0,[3,1200]]


And then do the following:



val quantileProbabilities = Array(0.3, 0.6)
val aft = new AFTSurvivalRegression()
.setQuantileProbabilities(quantileProbabilities)
.setQuantilesCol("quantiles")

val model = aft.fit(dfCust)

// Print the coefficients, intercept and scale parameter for AFT survival regression
println(s"Coefficients: $model.coefficients")
println(s"Intercept: $model.intercept")
println(s"Scale: $model.scale")
model.transform(dfCust).show(false)


But I do not understand:



  1. Is this the correct way to model the data as per Scala's documentation?

  2. How come I am not taking the customer ID into account anywhere?






scala apache-spark survival-analysis survival






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 20:37







EliSquared

















asked Mar 21 at 3:05









EliSquaredEliSquared

346516




346516












  • I'm not sure about your first question, it isn't clear for me. As per your second question, the default label, censor and features columns are respectively "label", "censor" and "features". That's why you didn't need to precise that explicitly.

    – eliasah
    Mar 21 at 9:30


















  • I'm not sure about your first question, it isn't clear for me. As per your second question, the default label, censor and features columns are respectively "label", "censor" and "features". That's why you didn't need to precise that explicitly.

    – eliasah
    Mar 21 at 9:30

















I'm not sure about your first question, it isn't clear for me. As per your second question, the default label, censor and features columns are respectively "label", "censor" and "features". That's why you didn't need to precise that explicitly.

– eliasah
Mar 21 at 9:30






I'm not sure about your first question, it isn't clear for me. As per your second question, the default label, censor and features columns are respectively "label", "censor" and "features". That's why you didn't need to precise that explicitly.

– eliasah
Mar 21 at 9:30













0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55273175%2fsurvival-aft-analysis-with-scala%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55273175%2fsurvival-aft-analysis-with-scala%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript