\section{Introduction}

Statistical analysis is usually introduced in introductory laboratory courses in first years of science studies \cite{taylor1997introduction,hughes2010measurements}. The typical approaches are based on performing manually repetitive observations, for example, measuring a time interval with a stopwatch under identical conditions. This kind of measurement gives slightly different results due to the fact in the real world there exist statistical fluctuations. The measurements obtained are usually examined from the statistical viewpoint plotting histograms, calculating mean values and standard deviations and, eventually, compared with those expected from a known distribution, typically a normal distribution. Commonly these experiments are tedious and require a lot of time to be able to perform an adequate number of measurements to perform the statistical analysis
(see for example the classical experiments proposed in Refs. \cite{fernando1976experiment,mathieson1970student}).


The use of smartphone sensors has been incorporated in Physics laboratories
in all the fields, see for example  \cite{vieyrafive,monteiro2022resource}.
Worth mentioning characteristics of  modern smartphones are the ability to measure simultaneously with more than one sensor \cite{monteiro2019physics} or
supplement the data with video analysis \cite{monteiro2021allies}.
In almost all the experiments, the focus is on the mean values reported by the sensors while the fluctuations play an annoying role. 
Recently, it has been proposed a novel approach to study uncertainties and errors in Physics laboratories taking the advantages provides by smartphone sensors \cite{monteiro2021using}. In this work, based on data recorded with the sensors present in many mobile devices, we propose a set of  experiments that can be performed at home to teach error and uncertainties. In particular we discuss the role of the digital resolution of the sensors and how to relate this quantify to the statistical magnitudes to determine the optimal number of repetitive measurements.

\section{A first approach to deal with statistics}


In this work we focus on the teaching of statistical uncertainties which due
to a multitude of causes are inherent to all physical measurements
\cite{taylor1997introduction}.  We assume that in a given experiment
an observation is repeated $N$ times under identical conditions
obtaining different results $x_i$, with $i=1,.. ,N$. It can be shown
that the best representative or \textit{estimate} of the set of values
is given by the mean value $\overline{x}$ defined as
\begin{equation}
 \overline{x}= \frac{1}{N} \sum_{i=1}^N x_i.
 \end{equation}
The deviation with respect to the mean value is identified with
$\epsilon_i= x_i - \overline{x}$. It can be shown that the mean value
defined as above minimizes the sum of the squared
deviations. Intuitively, it can be regarded as the
\textit{center-of-mass} of the set of the observations or equivalent
to the value \textit{closest} to all the other values.  In statistical
uncertainties it is of interest to quantify the dispersion of the values
around the mean value or, informally, the\textit{ width of the cloud}.
The standard deviation defined as
\begin{equation}
  \sigma = \sqrt{\frac{1}{N-1}\sum_{i=1}^N (x_i - \overline{x})^2}
\end{equation}
can be seen as a measure of this dispersion. If the number of
observations, $N$, is large enough, $\sigma$ it is characteristic of the set of all the possible observations and does not depend on the specific set of observations.  In practice, the uncertainty in the determination of a physical magnitude depends on the number of repeated measurements we have done.


The standard deviation, if $N$ is large enough, is characteristic of the set of all the possible observations whereas the standard error, or standard deviation of the mean, generally defined as $$\sigma(\bar{a_z}) = \sigma_{a_z}/\sqrt{N}$$  represents the margin of uncertainty of the mean value obtained in a particular
set of measurements \cite{taylor1997introduction}. The result of a specific measurement is usually expressed as
$\overline{a}_z \pm \sigma(\bar{a_z})$
representing the best estimate and the confidence in that value. 

It is worth highlighting that the standard deviation is related to the
degree to which an observation deviated from the mean value whereas
the standard error is an estimate of the uncertainty of the mean
value.  In a practical situation the standard uncertainty depends on the
number of measurements taken with $N^{-1/2}$. Then, given a set of $N$
measures the standard deviation gives an idea of the dispersion of an
ideal set of infinite measures while the standard uncertainty represents the
uncertainty of our set. This margin can be reduced by increasing the
number of measurements, however, the square-root implies that this
reduction is relatively slow.

\section{Errors and uncertainties using smartphone sensors}

Mobile devices such as smartphones or tablets include several sensors (accelerometer, magnetometer, ambient light sensor, among others) that can be used as an alternative proposal to deal with statistical distributions. The unavoidable fluctuations present in the several sensors, so annoying in any measurement, can be used, however, favourably, to illustrate basic concepts of statistical treatment of errors and uncertainties \cite{monteiro2021using}. Using these sensors, it is possible to acquire hundreds or thousands of repeated measurements of a physical magnitude in a few seconds and analyse them in the mobile device  or transferred to a personal computer or analysed in the cloud. 

\begin{figure}[h]
\begin{center}
\includegraphics[width=0.29\textwidth]{FIG1.png}
\caption{Phyphox screenshot of the vertical component of the accelerometer while the smartphone is resting on a table.}
\label{fig:screenshot}
\end{center}
\end{figure}

To access data registered by the sensors it is necessary to use an special
piece of software, or \textit{app}. There are many suitable options
available in the digital stores. In this proposal we mainly use the Phyphox app
\cite{staacks_2018} which stands out because of its friendly interface and the
 possibility to access to  experiments programmed or proposed by other users. 
As an example we show in Fig.~\ref{fig:screenshot} the statistics of the vertical component of the accelerometer value while the smartphone is simply resting on a table. The graph on the top is the temporal evolution of the values during an interval of about 20 $s$. We can observe that the values oscillate around the gravitational acceleration value. The corresponding histogram is plotted on the bottom panel where a Gaussian fit is overlapped. Mean value, standard deviation, bin size and number of measurements are also indicated on the bottom.


As mentioned before, sensor data can be analysed in the smartphone or  transferred
to a computer. Next, we show in Fig.~\ref{fig:z} the temporal evolution of the vertical acceleration (top panel). We also included in this graph horizontal lines at values
$\overline{x} \pm \sigma$, $\overline{x} \pm 2 \sigma$ and $\overline{x} \pm 3 \sigma$. These interval can be used to count 
the number of values in each interval and compare with the well-known expected percentages according to a Gaussian distribution.
In the bottom panel we show the histogram and the corresponding Gaussian fit using the
mean value and standard deviation of the experimental data.

\begin{figure}[h]
\begin{center}
\includegraphics[width=0.8\textwidth]{FIG3.png}
\includegraphics[width=0.8\textwidth]{FIG4.png}
\caption{Measurements of $z$ acceleration as a function of  time for the smartphone held on the hand (top panel) and the  histogram with a Gaussian fit (bottom panel).
}
\label{fig:z}
\end{center}
\end{figure}

An interesting point is to consider, taking advantage of the capability to quickly register data, different number
of repetitive measurements $N$ for the same experimental setup.
 In Table.~\ref{tabsigmaN} we report results of the mean value,  standard deviation and standard error
 for different length of these experimental series. This information is also plotted  in Fig.~\ref{fig:n} where we show the standard  uncertainty as a function of  $N$. As mentioned above, it is clear from that data that $\sigma_{a_z}$ is nearly
constant and, as a consequence, $\sigma(\bar{a_z})$ is proportional to
$N^{-1/2}$. According to our experience, this graph results more convincing to the students than theoretical explanations.

\begin{table}
 \begin{center}
\begin{tabular}{|c|c|c|c|} \hline 
$N$ & $\overline{x}$ & $\sigma$ & $\sigma_x$\\ \hline 
563 & 9,493 & 0,020 & 0,00085\\ 
1156 & 9,487 & 0,019 & 0,00054\\
1746 & 9,478 & 0,018 & 0,00044\\
2348 & 9,469 & 0,019 & 0,00039\\
2941 & 9,466 & 0,020 & 0,00036\\
3535 & 9,464 & 0,019 & 0,00032\\
4166 & 9,462 & 0,019 & 0,00029\\
4733 & 9,464 & 0,019 & 0,00027\\
5327 & 9,465 & 0,019 & 0,00026\\
5919 & 9,464 & 0,020 & 0,00026 \\ \hline
\end{tabular}
\caption{\label{tabsigmaN} Mean value, standard deviation and standard
  error as a function of the number of measures  corresponding to several experiments under identical conditions but with different number of measurements.}
\end{center}
\end{table}





\begin{figure}[h]
\begin{center}
\includegraphics[width=0.8\textwidth]{FIG6.png}
\caption{Standard error as a function of the number of repetitive measurements. We notice that the standard uncertainty
slowly decreases as we increase $N$.}
\label{fig:n}
\end{center}
\end{figure}





\begin{figure}[h]
\begin{center}
\includegraphics[width=0.89\textwidth]{FIG7a.png}
\includegraphics[width=0.89\textwidth]{FIG7b.png}
\caption{Phyphox screenshots for different values of $N$. We observe as the number of repetitive measurements is increased the histograms curve results closer to the expected Gaussian fit.}
\label{fig:screenshots}
\end{center}
\end{figure}






\section{Digital resolution and optimal number of measurements}


A closer look at the temporal evolution of the accelerometer data reveals that the distribution
in the vertical axis is not continuous but instead present discrete values separated by uniform intervals. The minimum interval corresponds to the digital resolution of the sensor.
In Fig.~\ref{fig:discrete} we present a zoom of the  $z$ component of the acceleration
in which we can better appreciate the discrete distribution. The digital resolution can be estimate
from this graph to be of the order of $10^{-3}$ m/s$^2$. 



\begin{figure}[h]
\begin{center}
\includegraphics[width=0.36\textwidth]{FIG5.png}
\caption{A zoom of the temporal evolution of the $z$ component of the acceleration where we can observe the discrete nature of the values reported by the sensor.}
\label{fig:discrete}
\end{center}
\end{figure}




The choice of $N$ in a specific experiment is a delicate question.  Indeed, if we could repeat the measurements infinite times the standard uncertainty would vanish and we could achieve a perfect knowledge of the best estimate.
However, as the decrease of the standard uncertainty with the number of observations is slow, it is impractical to increment  this number excessively. A common criterion  is to take a number of measurements,
often referred as the \textit{optimal number of measurements}, $N_{\mathrm{opt}}$,
such that the statistical uncertainty is of the same order as the  systematic  (or type B) errors. Here, in the absence of other sources of systematic errors, the standard uncertainty should be of the same order as the resolution of the digital instrument: $\sigma(\bar{a_z}) = \sigma_{a_z} /\sqrt{N_{opt}} \sim \delta$. In the  experiment depicted in Table~\ref{tabsigmaN} with a LG G3, the resolution is  $\delta=0.0012$ m/s$^2$, therefore $N_{\mathrm{opt}} \sim 250.$ It is worth emphasizing that this estimate is optimistic and must be examined in case of having other sources of systematic errors.


\section{Other applications}

An interesting experiment is to study the intensities of the fluctuations depending on the way in which the experimenter holds the device and the steadiness of the device is quantified by the standard deviation of a given temporal series.  This activity can be adapted to be proposed as a challenge to a group of students consisting in trying to hold the device as steadily as possible.
Another activity that can be performed is to propose that students assess the quality of a road as proposed in Ref.  \cite{harikrishnan2017vehicle}.  A means of transport, in this case a car, under similar conditions (speed) is employed, but other possibilities, such as a bike, are equally feasible.

Another interesting project is to study the intensities of the fluctuations depending on the way in which the experimenter holds his/her device.  This activity can be proposed as a challenge to the students consisting of trying to hold the device as steadily as possible. Another possibility (not recommended by the authors) is to study the fluctuations of the gait of a pedestrian as a function of the alcohol beverage intake, similarly to Ref.~\cite{zaki2020study}.




It is also possible to analyse the statistical character of other magnitudes different from the acceleration. To show another possibility,  Fig.~\ref{fig:mag} 
reproduces a screenshot of a similar experiment using, in this case, the magnetometer. This analysis can be useful when considering outdoor experiments
dealing with magnetic field as proposed in Ref. \cite{monteiro2020magnetic}.
 

\begin{figure}[h]
\begin{center}
\includegraphics[width=0.4\textwidth]{FIG2.png}
\caption{Phyphox screenshot showing an histogram and the  Gaussian fit
corresponding to  magnetometer data. Note that this data set in considerable noisier than that
obtained with the accelerometer.}
\label{fig:mag}
\end{center}
\end{figure}


\section{Closing remarks}

The activities discussed above were successfully proposed at our university to freshman Engineering and Physics students. In previous laboratory experiments students already knew the usefulness of the sensor to study several phenomena in which the noise was a factor to avoid. However,  when sensors were proposed to study fluctuations, they were surprised to discover a kind of underlying world. Despite having gone through statistical topics in several courses, the normal distribution appearing as an experimental fact rather than a mathematical consequence, was original. It is worth discussing how the distributions of the other sensors change. For example, magnetometer fluctuations, significantly influenced by  motors or ferromagnetic material in the vicinity, do not follow normal distributions.  Several challenges can be proposed in relation to sports, comfort evaluations  or quality control.


The main conclusion is that modern mobile-device sensors are useful tools for teaching error analysis and uncertainties. In this work we proposed several activities that can be performed to teach uncertainties and error analysis using digital instruments and the builtin sensors included in modern mobile devices. It is not difficult to obtain experimental distributions of fluctuations and compare them with the expected ones. It is shown that the distributions  usually obey normal (Gaussian) statistics; however, it is easy to obtain non normal distributions. The role of noise intensity, spreading or narrowing the distributions open up the possibilities of new applications. Holding the mobile device in different ways also gives an idea of how firmly it is held. Registering acceleration values in a car can assess the smoothness of a road. In our proposal, the lengthy and laborious manipulations of traditional approaches based on repetitive measurements, are avoided allowing teaching to focus on the fundamental concepts. These experiments could contribute to motivating students and showing them	the necessity of considering uncertainty analysis. 
Several possible extensions related to non-normal statistics can be considered,
such as Poisson distribution \cite{mathieson1970student}, distribution of maxima, Chauvenet criterion \cite{limb2017inefficacy}, or Benford's law \cite{bradley2009benford}. 

\textbf{Acknowledgments} We acknowledge financial support from grant Fisica Nolineal (ID 722) Programa Grupos I + D CSIC 2018 (UdelaR, Uruguay) and PEDECIBA (UdelaR, MEC, Uruguay).


\section*{References}

