<jupyter_start><jupyter_text>The first step in any data analysis is acquiring and munging the dataAn example data set can be found at:   https://jakecoltman.gitlab.io/website/post/pydata/Download the file output.txt and transform it into a format like below where the event column should be 0 if there's only one entry for an id, and 1 if there are two entries:End date = datetime.datetime(2016, 5, 3, 20, 36, 8, 92165)id,time_to_convert,age,male,event,search,brand<jupyter_code>####Data munging here
###Parametric Bayes
#Shout out to <NAME>
## Example fully worked model using toy data
## Adapted from http://blog.yhat.com/posts/estimating-user-lifetimes-with-pymc.html

alpha = pm.Uniform("alpha", 0,20) 
beta = pm.Uniform("beta", 0,20) 
obs = pm.Weibull('obs', alpha, beta, value = df["time_to_convert"], observed = True )
obs.random
@pm.potential
def censorfactor(obs=obs): 
    if np.any(obs>23 ): 
        return -100000
    else:
        return 0

mcmc = pm.MCMC([alpha, beta, obs, censorfactor ] )
mcmc.sample(5000, burn = 0)
pm.Matplot.plot(mcmc)
mcmc.trace("alpha")[:]<jupyter_output><empty_output><jupyter_text>Problems:     1 - Try to fit your data from section 1     2 - Use the results to plot the distribution of the median    Note that the media of a Weibull distribution is:$$β(log 2)^{1/α}$$<jupyter_code>#### Fit to your data here
#### Plot the distribution of the median<jupyter_output><empty_output><jupyter_text>Problems:        4 - Try adjusting the number of samples for burning and thinnning    5 - Try adjusting the prior and see how it affects the estimate<jupyter_code>#### Adjust burn and thin, both paramters of the mcmc sample function
#### Narrow and broaden prior<jupyter_output><empty_output><jupyter_text>Problems:        6 - Try using different distributions    7 - Bonus - try testing whether the median is greater than 14<jupyter_code>#### Different distributions
#### Hypothesis testing<jupyter_output><empty_output><jupyter_text>If we want to look at covariates, we need a new approach.  We'll use Cox proprtional hazards.  More information available at https://jakecoltman.gitlab.io/website/post/cox_proportional_hazard/To fit in python we use the module lifelines:http://lifelines.readthedocs.io/en/latest/<jupyter_code>### Fit a cox proprtional hazards model<jupyter_output><empty_output><jupyter_text>Once we've fit the data, we need to do something useful with it.  Try to do the following things:    1 - Plot the baseline survival function    2 - Predict the functions for a particular set of features    3 - Plot the survival function for two different set of features    4 - For your results in part 3 caculate how much more likely a death event is for one than the other for a given period of time<jupyter_code>#### Plot baseline hazard function
#### Predict
#### Plot survival functions for different covariates
#### Plot some odds<jupyter_output><empty_output><jupyter_text>Model selectionDifficult to do with classic tools (here)Problem:    1 - Calculate the BMA coefficient values        2 - Try running with different priors<jupyter_code>#### BMA Coefficient values
#### Different priors<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09271523178807947, 'fraction_numerical': 0.017660044150110375, 'mean_word_length': 4.809523809523809, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '565889', 'license': 'MIT', 'n_tokens_mistral': 1014, 'n_tokens_neox': 940, 'n_words': 359, 'path': 'Full.ipynb', 'repo_name': 'Journeyman08/BayesianSurvivalAnalysis', 'size': '3183'}