Public
Edited
Sep 12, 2023
Fork of Untitled
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// randomMoodValue = [d3.randomNormal(moodValue,sigma)()]; // Generate a single number
randomMoodValue = Array.from({length: n}, () => Math.floor(d3.randomNormal(moodValueMean,sigma)() )); //Generate an array of number
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
randomDateArray = (randomDateArrayReap.reduce(function(a,b){if(a.indexOf(b)<0)a.push(b);return a;},[]));
Insert cell
Insert cell
viewof firstDay = Inputs.date({value:"2020-12-10",label: "First Day I rate my mood:", max:new Date()})
Insert cell
Insert cell
randomDateArrayRaw = randomDateArray.flatMap(n => n.toISOString().split('T')[0]); //Format the date to yyyy-mm-dd
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function transCI(CIL) {
// const CIL_txt = 0,
if(CIL === null){
return "Please select a CI level"
}else if(CIL == 1){
return "1σ interval = 68%CI"
}else if(CIL == 2){
return "2σ interval = 95%CI"
}else if(CIL == 3){
return "3σ interval = 99.7%CI"
}else if(CIL == 4){
return "4σ interval = 99.99%CI"
}else if(CIL == 5){
return "5σ interval = 99.99994%CI (Paticle Physics standard)"
}
}
Insert cell
Insert cell
Insert cell
SleepStudyData.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
sleepHours = sleepstudydata.filter(sleepstudydata => sleepstudydata["Hours"] > 0) //Extract data from the csv doc to array, and filtered out missing data.
Insert cell
sleepHoursFilt = sleepHours.map(data => {
return data.Hours
})
// sleepHourArr = sleepHours.map(d => [d.Participant, d.Hours]) //I tried to extract two variables from the original data, but it doesn't shows in a json format. So I still used my clumpsy method here: extract varibables separatly and combine them in a function called jsonRecords().
Insert cell
Insert cell
Insert cell
sleepMean = Number(d3.mean(sleepHoursFilt).toString().match(/^\d+(?:\.\d{0,2})?/))
Insert cell
// sleepSigma = Math.floor(d3.deviation(hours))
sleepSigma = Number(d3.deviation(sleepHoursFilt).toString().match(/^\d+(?:\.\d{0,2})?/))
Insert cell
Insert cell
sleepData = jsonRecords2(parNo,sleepHoursFilt)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more