SlideShare a Scribd company logo
1 of 6
Download to read offline
SAMSI PMED Hands-on problem set
Go to https://github.com/johnnardini/SAMSI_PMED_UG and download patient_data.Rdata
1. Load in and plot some of the patients’ data from patient_exp_data.zip over time. What
can you infer about a patient’s growth rate immediately from the visualization of the
graph?
If data increase, then k > 0 , if data decreases then k <0
2. Plot patient 1’s data over time as well as the cost function over a range of values of k.
What do you think their value of k is? You may assume the initial volume of all
patients is x0=10.
You may suggest to students plotting log(J(k)) if they are having trouble finding the
minimum. The minimum value should appear to be about 0.56
3. Use linear regression to estimate Patient 1’s growth rate. How does this result change if
you use Nelder-Mead? And what is the variance in their data?
With linear regression, I get k=0.5541 with variance 394.62
With Nelder-Mear, I get k =0.5541 with variance 0.2406
4. Say that we label each patient’s tumor as either benign if k<= 0 and malignant if k > 0.
Estimate the value of k for all patients. Which patients are benign and which are
malignant? Estimate each patient’s variance to also understand how certain you can be
of this decision
Maligant = 1 2 4 5 7 9 10 11 13 14 15 16 17 18 19 20 23 28
[19] 29 30 31 32 33 35 36 37 38 39 40 42 43 44 45 46 47 48
[37] 51 52 53 54 55 57 58 59 60 61 62 63 64 65 67 68 69 70
[55] 71 72 73 74 75 76 78 79 80 81 82 83 85 86 88 90 91 92
[73] 93 94 95 96 97 98 99 100
Benign = 3 6 8 12 21 22 24 25 26 27 34 41 49 50 56 66 77 84 87 89
5. Load in patient data from patient_logistic_data.zip. Here, patient data is assumed to
satisfy the logistic equation with solution
𝑥𝑥(𝑡𝑡) =
𝐿𝐿
1+
𝐿𝐿−𝑥𝑥0
𝑥𝑥0
𝑒𝑒−𝑘𝑘𝑘𝑘
with growth rate k , carrying capacity L, and initial value x0. Estimate k and L for each
patient. You may assume x0 = 10 for all patients. The following are the k and L estimate
value I got for each patient using the Nelder-Mead algorithm.
k_vec L_vec
1 1.2654676 8.304699e-01
2 11.7619727 1.615752e+00
3 13.3091656 1.686880e+00
4 10.5019063 1.257752e+00
5 11.9382071 1.549083e+00
6 10.0669468 4.694007e-01
7 1.6670590 6.536226e-01
8 12.9964048 1.711225e+00
9 13.3811862 1.676909e+00
10 13.0833319 1.335633e+00
11 14.4863655 1.330378e+00
12 10.9678288 1.493734e+00
13 0.9265287 6.560393e-01
14 2.1182152 9.407196e-01
15 0.7059516 5.588547e-01
16 10.7339548 1.058486e+00
17 7.1478286 7.946702e-01
18 7.8916411 5.692626e-01
19 10.2350892 1.182629e+00
20 10.5346958 1.097555e+00
21 11.8639230 1.471730e+00
22 12.1852456 1.365304e+00
23 7.4915777 1.071662e+00
24 10.6187441 1.048962e+00
25 0.4432881 4.529418e-01
26 12.3712415 1.646684e+00
27 6.0712101 9.186066e-01
28 -0.1806004 -6.996339e-01
29 0.6034408 5.318405e-01
30 11.9395714 1.449614e+00
31 2.8736988 9.228771e-01
32 2.8315420 9.306702e-01
33 2.4555920 7.441670e-01
34 0.7160786 4.636150e-01
35 0.9213267 2.974153e-01
36 9.9875834 1.342497e+00
37 13.8232628 1.487993e+00
38 1.7737302 6.053922e-01
39 12.0958862 1.826433e+00
40 2.5666378 4.188325e-01
41 6.2475353 7.839956e-01
42 -0.7990190 -7.827030e+00
43 1.5900938 7.263686e-01
44 3.6497433 8.732344e-01
45 1.2833085 8.086346e-01
46 1.5211458 6.698975e-01
47 -0.6286231 1.573724e+00
48 -0.6973819 -1.406175e+01
49 -0.3390248 -1.349227e+00
50 14.7507714 1.266015e+00
51 1.5630759 7.221006e-01
52 -1.1603026 -1.507511e+05
53 0.5031531 4.914686e-01
54 9.0257029 9.444095e-01
55 10.7058497 1.528645e+00
56 2.4128777 9.052124e-01
57 10.6270107 4.553923e-01
58 13.3422047 1.586013e+00
59 1.8767435 8.213170e-01
60 -0.6424673 -7.090889e+04
61 0.7988525 4.325125e-01
62 2.1325382 1.120922e+00
63 9.9243841 1.123222e+00
64 0.8735720 5.433013e-01
65 10.5755356 1.239817e+00
66 10.2701606 1.165054e+00
67 13.8641654 1.793154e+00
68 1.6120830 5.336628e-01
69 4.9293382 9.899117e-01
70 0.4033716 3.789583e-01
71 6.0989504 1.029101e+00
72 1.0011041 7.258936e-01
73 10.7572906 1.211045e+00
74 8.0477779 1.246573e+00
75 10.3258385 6.495912e-01
76 11.3413498 1.548661e+00
77 13.4037659 1.823467e+00
78 2.8745333 9.223312e-01
79 1.4748666 8.945001e-01
80 11.4489941 1.020913e+00
81 13.2716058 1.487321e+00
82 5.9542093 1.205005e+00
83 2.5566369 7.469612e-01
84 11.7133624 1.135658e+00
85 0.1483344 1.459890e-01
86 6.5461769 1.023967e+00
87 13.1869660 1.031079e+00
88 12.3569027 1.065389e+00
89 2.7347862 9.543741e-01
90 10.2390822 1.700551e+00
91 0.6661322 3.157147e-01
92 1.8630617 8.143959e-01
93 1.4710117 7.340427e-01
94 4.3200184 9.898926e-01
95 12.9558599 1.782502e+00
96 1.2616897 5.911347e-01
97 11.8146558 1.613349e+00
98 1.8061573 1.003933e+00
99 6.2816562 7.106089e-01
100 10.1287215 1.243248e+00
#question 1
X<-read.csv("patient2.csv")
plot(X$t,X$logvolume)
#question 2
J<-function(k){sum((X$volume-10*exp(k*X$t))^2)}
k_range <- seq(.4,.6,by=0.02)
J_vec = matrix(length(k_range),1)
for (i in seq(1,length(k_range),by=1)){
J_vec[i] <- J(k_range[i])
}
plot(k_range,J_vec)
#question 3
linearMod <- lm(logvolume~t,data=X)
linearMod
1/(length(X$t)-1)*J(.5541)
NM_result <- optim_nm(J,k=1)
1/(length(X$t)-1)*J(NM_result$par)
#question 4
benign=c()
malignant =c()
for(i in 1:100){
X<-read.csv(paste0("patient",toString(i),".csv"))
J<-function(k){sum((X$volume-10*exp(k*X$t))^2)}
NM_result <- optim_nm(J,k=1,start=0.5)
show(NM_result$par)
if (NM_result$par > 0 ){malignant <- c(malignant,i)} else {{benign <- c(benign,i)}}
}
benign
malignant
#question 5
k_vec <- c()
L_vec <- c()
x0<-10
x_log <- function(k,L,t){L/(1+((L-x0)/x0)*exp(-k*t))}
for(i in 1:100){
X<-read.csv(paste0("patient_logistic_",toString(i),".csv"))
J<-function(x){sum((X$volume-x_log(x[1],x[2],X$t))^2)}
NM_result <- optim_nm(J,k=2)
k_vec <- c(k_vec,NM_result$par[1])
L_vec <- c(L_vec,NM_result$par[2])
}
k_vec
L_vec

More Related Content

More from The Statistical and Applied Mathematical Sciences Institute

More from The Statistical and Applied Mathematical Sciences Institute (20)

Causal Inference Opening Workshop - Bipartite Causal Inference with Interfere...
Causal Inference Opening Workshop - Bipartite Causal Inference with Interfere...Causal Inference Opening Workshop - Bipartite Causal Inference with Interfere...
Causal Inference Opening Workshop - Bipartite Causal Inference with Interfere...
 
Causal Inference Opening Workshop - Bridging the Gap Between Causal Literatur...
Causal Inference Opening Workshop - Bridging the Gap Between Causal Literatur...Causal Inference Opening Workshop - Bridging the Gap Between Causal Literatur...
Causal Inference Opening Workshop - Bridging the Gap Between Causal Literatur...
 
Causal Inference Opening Workshop - Some Applications of Reinforcement Learni...
Causal Inference Opening Workshop - Some Applications of Reinforcement Learni...Causal Inference Opening Workshop - Some Applications of Reinforcement Learni...
Causal Inference Opening Workshop - Some Applications of Reinforcement Learni...
 
Causal Inference Opening Workshop - Bracketing Bounds for Differences-in-Diff...
Causal Inference Opening Workshop - Bracketing Bounds for Differences-in-Diff...Causal Inference Opening Workshop - Bracketing Bounds for Differences-in-Diff...
Causal Inference Opening Workshop - Bracketing Bounds for Differences-in-Diff...
 
Causal Inference Opening Workshop - Assisting the Impact of State Polcies: Br...
Causal Inference Opening Workshop - Assisting the Impact of State Polcies: Br...Causal Inference Opening Workshop - Assisting the Impact of State Polcies: Br...
Causal Inference Opening Workshop - Assisting the Impact of State Polcies: Br...
 
Causal Inference Opening Workshop - Experimenting in Equilibrium - Stefan Wag...
Causal Inference Opening Workshop - Experimenting in Equilibrium - Stefan Wag...Causal Inference Opening Workshop - Experimenting in Equilibrium - Stefan Wag...
Causal Inference Opening Workshop - Experimenting in Equilibrium - Stefan Wag...
 
Causal Inference Opening Workshop - Targeted Learning for Causal Inference Ba...
Causal Inference Opening Workshop - Targeted Learning for Causal Inference Ba...Causal Inference Opening Workshop - Targeted Learning for Causal Inference Ba...
Causal Inference Opening Workshop - Targeted Learning for Causal Inference Ba...
 
Causal Inference Opening Workshop - Bayesian Nonparametric Models for Treatme...
Causal Inference Opening Workshop - Bayesian Nonparametric Models for Treatme...Causal Inference Opening Workshop - Bayesian Nonparametric Models for Treatme...
Causal Inference Opening Workshop - Bayesian Nonparametric Models for Treatme...
 
2019 Fall Series: Special Guest Lecture - Adversarial Risk Analysis of the Ge...
2019 Fall Series: Special Guest Lecture - Adversarial Risk Analysis of the Ge...2019 Fall Series: Special Guest Lecture - Adversarial Risk Analysis of the Ge...
2019 Fall Series: Special Guest Lecture - Adversarial Risk Analysis of the Ge...
 
2019 Fall Series: Professional Development, Writing Academic Papers…What Work...
2019 Fall Series: Professional Development, Writing Academic Papers…What Work...2019 Fall Series: Professional Development, Writing Academic Papers…What Work...
2019 Fall Series: Professional Development, Writing Academic Papers…What Work...
 
2019 GDRR: Blockchain Data Analytics - Machine Learning in/for Blockchain: Fu...
2019 GDRR: Blockchain Data Analytics - Machine Learning in/for Blockchain: Fu...2019 GDRR: Blockchain Data Analytics - Machine Learning in/for Blockchain: Fu...
2019 GDRR: Blockchain Data Analytics - Machine Learning in/for Blockchain: Fu...
 
2019 GDRR: Blockchain Data Analytics - QuTrack: Model Life Cycle Management f...
2019 GDRR: Blockchain Data Analytics - QuTrack: Model Life Cycle Management f...2019 GDRR: Blockchain Data Analytics - QuTrack: Model Life Cycle Management f...
2019 GDRR: Blockchain Data Analytics - QuTrack: Model Life Cycle Management f...
 
2019 GDRR: Blockchain Data Analytics - Modeling Cryptocurrency Markets with T...
2019 GDRR: Blockchain Data Analytics - Modeling Cryptocurrency Markets with T...2019 GDRR: Blockchain Data Analytics - Modeling Cryptocurrency Markets with T...
2019 GDRR: Blockchain Data Analytics - Modeling Cryptocurrency Markets with T...
 
2019 GDRR: Blockchain Data Analytics - Tracking Criminals by Following the Mo...
2019 GDRR: Blockchain Data Analytics - Tracking Criminals by Following the Mo...2019 GDRR: Blockchain Data Analytics - Tracking Criminals by Following the Mo...
2019 GDRR: Blockchain Data Analytics - Tracking Criminals by Following the Mo...
 
2019 GDRR: Blockchain Data Analytics - Disclosure in the World of Cryptocurre...
2019 GDRR: Blockchain Data Analytics - Disclosure in the World of Cryptocurre...2019 GDRR: Blockchain Data Analytics - Disclosure in the World of Cryptocurre...
2019 GDRR: Blockchain Data Analytics - Disclosure in the World of Cryptocurre...
 
2019 GDRR: Blockchain Data Analytics - Real World Adventures at a Cryptocurre...
2019 GDRR: Blockchain Data Analytics - Real World Adventures at a Cryptocurre...2019 GDRR: Blockchain Data Analytics - Real World Adventures at a Cryptocurre...
2019 GDRR: Blockchain Data Analytics - Real World Adventures at a Cryptocurre...
 
2019 GDRR: Blockchain Data Analytics - Dissecting Blockchain Price Analytics...
2019 GDRR: Blockchain Data Analytics  - Dissecting Blockchain Price Analytics...2019 GDRR: Blockchain Data Analytics  - Dissecting Blockchain Price Analytics...
2019 GDRR: Blockchain Data Analytics - Dissecting Blockchain Price Analytics...
 
2019 GDRR: Blockchain Data Analytics - ChainNet: Learning on Blockchain Graph...
2019 GDRR: Blockchain Data Analytics - ChainNet: Learning on Blockchain Graph...2019 GDRR: Blockchain Data Analytics - ChainNet: Learning on Blockchain Graph...
2019 GDRR: Blockchain Data Analytics - ChainNet: Learning on Blockchain Graph...
 
2019 GDRR: Blockchain Data Analytics - Cryptocurrency and blockchain analysis...
2019 GDRR: Blockchain Data Analytics - Cryptocurrency and blockchain analysis...2019 GDRR: Blockchain Data Analytics - Cryptocurrency and blockchain analysis...
2019 GDRR: Blockchain Data Analytics - Cryptocurrency and blockchain analysis...
 
2019 GDRR: Blockchain Data Analytics - Cryptocurrency and blockchain analysis...
2019 GDRR: Blockchain Data Analytics - Cryptocurrency and blockchain analysis...2019 GDRR: Blockchain Data Analytics - Cryptocurrency and blockchain analysis...
2019 GDRR: Blockchain Data Analytics - Cryptocurrency and blockchain analysis...
 

Recently uploaded

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

PMED Undergraduate Workshop - Hands on Demos for PMED in R Software (Hands on Solution) - John Nardini, October 22, 2018

  • 1. SAMSI PMED Hands-on problem set Go to https://github.com/johnnardini/SAMSI_PMED_UG and download patient_data.Rdata 1. Load in and plot some of the patients’ data from patient_exp_data.zip over time. What can you infer about a patient’s growth rate immediately from the visualization of the graph? If data increase, then k > 0 , if data decreases then k <0 2. Plot patient 1’s data over time as well as the cost function over a range of values of k. What do you think their value of k is? You may assume the initial volume of all patients is x0=10. You may suggest to students plotting log(J(k)) if they are having trouble finding the minimum. The minimum value should appear to be about 0.56 3. Use linear regression to estimate Patient 1’s growth rate. How does this result change if you use Nelder-Mead? And what is the variance in their data? With linear regression, I get k=0.5541 with variance 394.62 With Nelder-Mear, I get k =0.5541 with variance 0.2406 4. Say that we label each patient’s tumor as either benign if k<= 0 and malignant if k > 0. Estimate the value of k for all patients. Which patients are benign and which are malignant? Estimate each patient’s variance to also understand how certain you can be of this decision Maligant = 1 2 4 5 7 9 10 11 13 14 15 16 17 18 19 20 23 28 [19] 29 30 31 32 33 35 36 37 38 39 40 42 43 44 45 46 47 48 [37] 51 52 53 54 55 57 58 59 60 61 62 63 64 65 67 68 69 70 [55] 71 72 73 74 75 76 78 79 80 81 82 83 85 86 88 90 91 92 [73] 93 94 95 96 97 98 99 100 Benign = 3 6 8 12 21 22 24 25 26 27 34 41 49 50 56 66 77 84 87 89 5. Load in patient data from patient_logistic_data.zip. Here, patient data is assumed to satisfy the logistic equation with solution 𝑥𝑥(𝑡𝑡) = 𝐿𝐿 1+ 𝐿𝐿−𝑥𝑥0 𝑥𝑥0 𝑒𝑒−𝑘𝑘𝑘𝑘 with growth rate k , carrying capacity L, and initial value x0. Estimate k and L for each patient. You may assume x0 = 10 for all patients. The following are the k and L estimate value I got for each patient using the Nelder-Mead algorithm. k_vec L_vec 1 1.2654676 8.304699e-01 2 11.7619727 1.615752e+00
  • 2. 3 13.3091656 1.686880e+00 4 10.5019063 1.257752e+00 5 11.9382071 1.549083e+00 6 10.0669468 4.694007e-01 7 1.6670590 6.536226e-01 8 12.9964048 1.711225e+00 9 13.3811862 1.676909e+00 10 13.0833319 1.335633e+00 11 14.4863655 1.330378e+00 12 10.9678288 1.493734e+00 13 0.9265287 6.560393e-01 14 2.1182152 9.407196e-01 15 0.7059516 5.588547e-01 16 10.7339548 1.058486e+00 17 7.1478286 7.946702e-01 18 7.8916411 5.692626e-01 19 10.2350892 1.182629e+00 20 10.5346958 1.097555e+00 21 11.8639230 1.471730e+00 22 12.1852456 1.365304e+00 23 7.4915777 1.071662e+00 24 10.6187441 1.048962e+00 25 0.4432881 4.529418e-01 26 12.3712415 1.646684e+00 27 6.0712101 9.186066e-01 28 -0.1806004 -6.996339e-01 29 0.6034408 5.318405e-01 30 11.9395714 1.449614e+00 31 2.8736988 9.228771e-01 32 2.8315420 9.306702e-01 33 2.4555920 7.441670e-01 34 0.7160786 4.636150e-01 35 0.9213267 2.974153e-01 36 9.9875834 1.342497e+00 37 13.8232628 1.487993e+00 38 1.7737302 6.053922e-01 39 12.0958862 1.826433e+00 40 2.5666378 4.188325e-01 41 6.2475353 7.839956e-01 42 -0.7990190 -7.827030e+00 43 1.5900938 7.263686e-01 44 3.6497433 8.732344e-01 45 1.2833085 8.086346e-01 46 1.5211458 6.698975e-01
  • 3. 47 -0.6286231 1.573724e+00 48 -0.6973819 -1.406175e+01 49 -0.3390248 -1.349227e+00 50 14.7507714 1.266015e+00 51 1.5630759 7.221006e-01 52 -1.1603026 -1.507511e+05 53 0.5031531 4.914686e-01 54 9.0257029 9.444095e-01 55 10.7058497 1.528645e+00 56 2.4128777 9.052124e-01 57 10.6270107 4.553923e-01 58 13.3422047 1.586013e+00 59 1.8767435 8.213170e-01 60 -0.6424673 -7.090889e+04 61 0.7988525 4.325125e-01 62 2.1325382 1.120922e+00 63 9.9243841 1.123222e+00 64 0.8735720 5.433013e-01 65 10.5755356 1.239817e+00 66 10.2701606 1.165054e+00 67 13.8641654 1.793154e+00 68 1.6120830 5.336628e-01 69 4.9293382 9.899117e-01 70 0.4033716 3.789583e-01 71 6.0989504 1.029101e+00 72 1.0011041 7.258936e-01 73 10.7572906 1.211045e+00 74 8.0477779 1.246573e+00 75 10.3258385 6.495912e-01 76 11.3413498 1.548661e+00 77 13.4037659 1.823467e+00 78 2.8745333 9.223312e-01 79 1.4748666 8.945001e-01 80 11.4489941 1.020913e+00 81 13.2716058 1.487321e+00 82 5.9542093 1.205005e+00 83 2.5566369 7.469612e-01 84 11.7133624 1.135658e+00 85 0.1483344 1.459890e-01 86 6.5461769 1.023967e+00 87 13.1869660 1.031079e+00 88 12.3569027 1.065389e+00 89 2.7347862 9.543741e-01 90 10.2390822 1.700551e+00
  • 4. 91 0.6661322 3.157147e-01 92 1.8630617 8.143959e-01 93 1.4710117 7.340427e-01 94 4.3200184 9.898926e-01 95 12.9558599 1.782502e+00 96 1.2616897 5.911347e-01 97 11.8146558 1.613349e+00 98 1.8061573 1.003933e+00 99 6.2816562 7.106089e-01 100 10.1287215 1.243248e+00
  • 5. #question 1 X<-read.csv("patient2.csv") plot(X$t,X$logvolume) #question 2 J<-function(k){sum((X$volume-10*exp(k*X$t))^2)} k_range <- seq(.4,.6,by=0.02) J_vec = matrix(length(k_range),1) for (i in seq(1,length(k_range),by=1)){ J_vec[i] <- J(k_range[i]) } plot(k_range,J_vec) #question 3 linearMod <- lm(logvolume~t,data=X) linearMod 1/(length(X$t)-1)*J(.5541) NM_result <- optim_nm(J,k=1) 1/(length(X$t)-1)*J(NM_result$par) #question 4 benign=c() malignant =c() for(i in 1:100){ X<-read.csv(paste0("patient",toString(i),".csv")) J<-function(k){sum((X$volume-10*exp(k*X$t))^2)} NM_result <- optim_nm(J,k=1,start=0.5)
  • 6. show(NM_result$par) if (NM_result$par > 0 ){malignant <- c(malignant,i)} else {{benign <- c(benign,i)}} } benign malignant #question 5 k_vec <- c() L_vec <- c() x0<-10 x_log <- function(k,L,t){L/(1+((L-x0)/x0)*exp(-k*t))} for(i in 1:100){ X<-read.csv(paste0("patient_logistic_",toString(i),".csv")) J<-function(x){sum((X$volume-x_log(x[1],x[2],X$t))^2)} NM_result <- optim_nm(J,k=2) k_vec <- c(k_vec,NM_result$par[1]) L_vec <- c(L_vec,NM_result$par[2]) } k_vec L_vec