LS 40 (Life Science) Homework 7 Solutions (Lecture 1 W21)updated in Jan 2021
Homework 7 Solutions Adapted by Ashley Van Reynolds from previous solutions updated on March 2021 by Ana Gomez Scoring: 40 points total: Completion Points: 21, Accuracy Points: 19, on all problems except 5 & 6 1. Program a function for (“chi-abs”) and use to repeat the PrEP |expected −observed| analysis you did in lab. Are the results of the two analyses consistent? 2 completion points, 2 accuracy points As given in Lab 7, the data is: Drug Placebo Infected 36 64 Not Infected In [4]: import numpy as np import seaborn as sns import pandas as pd import t as plt |χ| = ∑ expected − observed expected In [2]: # Define chi-abs function # Purpose: compute chi-abs for any arrays of observed and expected data # Inputs: 2 arrays of same dimensions (observed, expected data for same study) # Outputs: chi-abs value def chi_abs(obs, exp): result=(((obs-exp))/exp) return result In [5]: # From Lab 7: # Enter observed data obs = ([[36, 64], [1215, 1184]]) # Calculate column totals total_drug = (obs[:,0]) # sum column 0 total_placebo = (obs[:,1]) # sum column 1 3/7/2021 Homework 7 Solutions (Lecture 1 S20) file:///home/user/Assignment%20Solutions%2021W/Homework%20Solutions/Homework%207%20Solutions%20(Lecture%201%20… 2/12 array([[ 50., 49.], [1200., 1198.]]) 0.0088 # Calculate row totals total_infected = (obs[0,:]) # sum row 0 total_uninfected = (obs[1,:]) # sum row 1 # Calculate total number of patients n = (obs) # Expected value is (sum of row )/n x (sum of column) # For example, overall probability of infection = total_infected/n, #so number of expected patients with drug & infected = #overall probability of infection * # of patients with drug # = total_infected/n*total_drug expected = ([[total_infected/n*total_drug, total_infected/n*total_placebo], [total_uninfected/n*total_drug, total_uninfected/n*total_placebo]]) expected Out[5]: In [9]: # Perform 10,000 simulations and calculate p-value #(same as in Lab 7, but calculating chi-abs) obschiabs=chi_abs(obs, expected) results=(10000) sim=([2,2]) # Box combines all infected and uninfected from both drug and placebo groups #so each individual has same overall probability of infection for i in range(10000): box=["I"]*total_infected + ["NI"]*total_uninfected drug_resample=e(box, total_drug) sim[0,0]=(drug_resample == "I") sim[1,0]=(drug_resample == "NI") placebo_resample = e(box, total_placebo) sim[0,1]=(placebo_resample == "I") sim[1,1]=(placebo_resample == "NI") results[i]=chi_abs(sim, expected) p=ot(results, kde=False) ne(obschiabs,color="mediumvioletred") count=(results = obschiabs) pval=count/10000 pval # In Lab 7, we calculated a p-value using chi-squared of about 0.0178. # The results of the twoanalyses are fairly consistent, although we couldn't # reject the null hypothesis using chi-squared if alpha = 0.01. With a p-value # of 0.0088, we can definitely reject the null hypothesis and say that the drug # has a significant effect on the odds of being infected with HIV. # In combination with other research and expert opinions, we can recommend # that patients at risk of HIV infection use PrEP drugs.
Geschreven voor
- Instelling
- University Of California - Los Angeles
- Vak
- Life Science
Documentinformatie
- Geüpload op
- 9 juli 2021
- Aantal pagina's
- 12
- Geschreven in
- 2021/2022
- Type
- Tentamen (uitwerkingen)
- Bevat
- Vragen en antwoorden
Onderwerpen
-
ls 40 life science homework 7 solutions lecture 1 w21updated in jan 2021
-
ls 40 life science homework 7 solutions
-
ls 40 life science